From e04273df572f65085646ae2f5179e8421f47e707 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 17 Apr 2015 11:47:29 +0200 Subject: [PATCH 1/2] fixed regression to 2.6.4 which surfaced e.g. in lost stdout capture printing when tests raised SystemExit. --HG-- branch : systemexit --- CHANGELOG | 4 ++++ _pytest/core.py | 2 +- testing/test_core.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 11445503c..056075fbf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,10 @@ - Support building wheels by using environment markers for the requirements. Thanks Ionel Maries Cristian. +- fixed regression to 2.6.4 which surfaced e.g. in lost stdout capture printing + when tests raised SystemExit. Thanks Holger Krekel. + + 2.7.0 (compared to 2.6.4) ----------------------------- diff --git a/_pytest/core.py b/_pytest/core.py index 6822e22fd..134a93ed0 100644 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -121,7 +121,7 @@ class CallOutcome: def __init__(self, func): try: self.result = func() - except Exception: + except BaseException: self.excinfo = sys.exc_info() def force_result(self, result): diff --git a/testing/test_core.py b/testing/test_core.py index 1ab39f665..631e88ae9 100644 --- a/testing/test_core.py +++ b/testing/test_core.py @@ -607,6 +607,21 @@ class TestMultiCall: assert "m1" in str(ex.value) assert "test_core.py:" in str(ex.value) + @pytest.mark.parametrize("exc", [ValueError, SystemExit]) + def test_hookwrapper_exception(self, exc): + l = [] + def m1(): + l.append("m1 init") + yield None + l.append("m1 finish") + m1.hookwrapper = True + + def m2(): + raise exc + with pytest.raises(exc): + MultiCall([m2, m1], {}).execute() + assert l == ["m1 init", "m1 finish"] + class TestHookRelay: def test_happypath(self): From 173bd13ece77e4b88c49fa5c45c89290dca4f10e Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 17 Apr 2015 11:57:09 +0200 Subject: [PATCH 2/2] backport Y->y fix from floris --HG-- branch : pytest-2.7 --- _pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/python.py b/_pytest/python.py index 292054a0c..7dd4095b8 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1451,7 +1451,7 @@ class FixtureRequest(FuncargnamesCompatAttr): if scopemismatch(invoking_scope, requested_scope): # try to report something helpful lines = self._factorytraceback() - pytest.fail("ScopeMismatch: you tried to access the %r scoped " + pytest.fail("ScopeMismatch: You tried to access the %r scoped " "fixture %r with a %r scoped request object, " "involved factories\n%s" %( (requested_scope, argname, invoking_scope, "\n".join(lines))),