From 9d64d7e27a746f799ef1d381a319a916484ceb69 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 28 Jan 2010 15:36:27 +0100 Subject: [PATCH] refine setup ordering some more - test and avoid a problem with funcarg setups where the surrounding setup_module would fail, but the funcarg setup still be called (which might assume that setup_module has been called so would raise a confusing error) --HG-- branch : trunk --- py/_plugin/pytest_runner.py | 8 ++++---- testing/plugin/test_pytest_runner_xunit.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/py/_plugin/pytest_runner.py b/py/_plugin/pytest_runner.py index 6814fb204..11b068a0c 100644 --- a/py/_plugin/pytest_runner.py +++ b/py/_plugin/pytest_runner.py @@ -248,6 +248,10 @@ class SetupState(object): if self.stack == needed_collectors[:len(self.stack)]: break self._pop_and_teardown() + # check if the last collection node has raised an error + for col in self.stack: + if hasattr(col, '_prepare_exc'): + py.builtin._reraise(*col._prepare_exc) for col in needed_collectors[len(self.stack):]: self.stack.append(col) try: @@ -255,7 +259,3 @@ class SetupState(object): except Exception: col._prepare_exc = sys.exc_info() raise - # check if the last collection node has raised an error - for col in self.stack: - if hasattr(col, '_prepare_exc'): - py.builtin._reraise(*col._prepare_exc) diff --git a/testing/plugin/test_pytest_runner_xunit.py b/testing/plugin/test_pytest_runner_xunit.py index 77ed35e9a..0d525b95b 100644 --- a/testing/plugin/test_pytest_runner_xunit.py +++ b/testing/plugin/test_pytest_runner_xunit.py @@ -186,5 +186,27 @@ def test_setup_fails_again_on_all_tests(testdir): ]) assert "passed" not in result.stdout.str() +def test_setup_funcarg_setup_not_called_if_outer_scope_fails(testdir): + p = testdir.makepyfile(""" + import py + def setup_module(mod): + raise ValueError(42) + def pytest_funcarg__hello(request): + raise ValueError(43) + def test_function1(hello): + pass + def test_function2(hello): + pass + """) + result = testdir.runpytest(p) + result.stdout.fnmatch_lines([ + "*function1*", + "*ValueError*42*", + "*function2*", + "*ValueError*42*", + "*2 error*" + ]) + assert "43" not in result.stdout.str() +