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
This commit is contained in:
holger krekel 2010-01-28 15:36:27 +01:00
parent a2af204687
commit 9d64d7e27a
2 changed files with 26 additions and 4 deletions

View File

@ -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)

View File

@ -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()