| commit 1627: | 0c6cafb6f4e6 |
| parent 1626: | b27a62c65746 |
| branch: | trunk |
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)
hpk
8 weeks ago
8 weeks ago
Changed (Δ613 bytes):
raw changeset »
py/_plugin/pytest_runner.py (4 lines added, 4 lines removed)
testing/plugin/test_pytest_runner_xunit.py (22 lines added, 0 lines removed)
Up to file-list py/_plugin/pytest_runner.py:
| … | … | @@ -248,6 +248,10 @@ class SetupState(object): |
248 |
248 |
if self.stack == needed_collectors[:len(self.stack)]: |
249 |
249 |
break |
250 |
250 |
self._pop_and_teardown() |
251 |
# check if the last collection node has raised an error |
|
252 |
for col in self.stack: |
|
253 |
if hasattr(col, '_prepare_exc'): |
|
254 |
py.builtin._reraise(*col._prepare_exc) |
|
251 |
255 |
for col in needed_collectors[len(self.stack):]: |
252 |
256 |
self.stack.append(col) |
253 |
257 |
try: |
| … | … | @@ -255,7 +259,3 @@ class SetupState(object): |
255 |
259 |
except Exception: |
256 |
260 |
col._prepare_exc = sys.exc_info() |
257 |
261 |
raise |
258 |
# check if the last collection node has raised an error |
|
259 |
for col in self.stack: |
|
260 |
if hasattr(col, '_prepare_exc'): |
|
261 |
py.builtin._reraise(*col._prepare_exc) |
Up to file-list testing/plugin/test_pytest_runner_xunit.py:
| … | … | @@ -186,5 +186,27 @@ def test_setup_fails_again_on_all_tests( |
186 |
186 |
]) |
187 |
187 |
assert "passed" not in result.stdout.str() |
188 |
188 |
|
189 |
def test_setup_funcarg_setup_not_called_if_outer_scope_fails(testdir): |
|
190 |
p = testdir.makepyfile(""" |
|
191 |
import py |
|
192 |
def setup_module(mod): |
|
193 |
raise ValueError(42) |
|
194 |
def pytest_funcarg__hello(request): |
|
195 |
raise ValueError(43) |
|
196 |
def test_function1(hello): |
|
197 |
pass |
|
198 |
def test_function2(hello): |
|
199 |
pass |
|
200 |
""") |
|
201 |
result = testdir.runpytest(p) |
|
202 |
result.stdout.fnmatch_lines([ |
|
203 |
"*function1*", |
|
204 |
"*ValueError*42*", |
|
205 |
"*function2*", |
|
206 |
"*ValueError*42*", |
|
207 |
"*2 error*" |
|
208 |
]) |
|
209 |
assert "43" not in result.stdout.str() |
|
189 |
210 |
|
190 |
211 |
|
212 |
