diff --git a/_pytest/runner.py b/_pytest/runner.py index 345080db0..3a6af4abc 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -333,10 +333,11 @@ class SetupState(object): fin = finalizers.pop() try: fin() - except KeyboardInterrupt: - raise - except: - exc = py.std.sys.exc_info() + except Exception: + # XXX Only first exception will be seen by user, + # ideally all should be reported. + if not exc: + exc = sys.exc_info() if exc: py.builtin._reraise(*exc) diff --git a/testing/test_runner.py b/testing/test_runner.py index 8a6f4f839..4ca45ec40 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -58,6 +58,19 @@ class TestSetupState: assert err.value.args == ('oops',) assert r == ['fin3', 'fin1'] + def test_teardown_multiple_fail(self, testdir): + # Ensure the first exception is the one which is re-raised. + # Ideally both would be reported however. + def fin1(): raise Exception('oops1') + def fin2(): raise Exception('oops2') + item = testdir.getitem("def test_func(): pass") + ss = runner.SetupState() + ss.addfinalizer(fin1, item) + ss.addfinalizer(fin2, item) + with pytest.raises(Exception) as err: + ss._callfinalizers(item) + assert err.value.args == ('oops2',) + class BaseFunctionalTests: def test_passfunction(self, testdir):