Correctly report teardown fixture errors
This commit is contained in:
parent
f017df443a
commit
7176470866
1
AUTHORS
1
AUTHORS
|
@ -54,6 +54,7 @@ Aviral Verma
|
||||||
Aviv Palivoda
|
Aviv Palivoda
|
||||||
Babak Keyvani
|
Babak Keyvani
|
||||||
Barney Gale
|
Barney Gale
|
||||||
|
Ben Brown
|
||||||
Ben Gartner
|
Ben Gartner
|
||||||
Ben Webb
|
Ben Webb
|
||||||
Benjamin Peterson
|
Benjamin Peterson
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix reporting of teardown errors in session and module scoped fixtures when `--maxfail=1`.
|
|
@ -179,6 +179,9 @@ def pytest_runtest_call(item: Item) -> None:
|
||||||
|
|
||||||
def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None:
|
def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None:
|
||||||
_update_current_test_var(item, "teardown")
|
_update_current_test_var(item, "teardown")
|
||||||
|
# If the session is about to fail, teardown everything - this is necessary
|
||||||
|
# to correctly report fixture teardown errors (see #11706)
|
||||||
|
nextitem = None if item.session.shouldfail else nextitem
|
||||||
item.session._setupstate.teardown_exact(nextitem)
|
item.session._setupstate.teardown_exact(nextitem)
|
||||||
_update_current_test_var(item, None)
|
_update_current_test_var(item, None)
|
||||||
|
|
||||||
|
|
|
@ -1087,3 +1087,25 @@ def test_outcome_exception_bad_msg() -> None:
|
||||||
with pytest.raises(TypeError) as excinfo:
|
with pytest.raises(TypeError) as excinfo:
|
||||||
OutcomeException(func) # type: ignore
|
OutcomeException(func) # type: ignore
|
||||||
assert str(excinfo.value) == expected
|
assert str(excinfo.value) == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_teardown_session_failed(pytester: Pytester) -> None:
|
||||||
|
"""Test that fixture teardown failures are reported after a test fails."""
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def baz():
|
||||||
|
yield
|
||||||
|
pytest.fail("This is a failing fixture")
|
||||||
|
|
||||||
|
def test_foo(baz):
|
||||||
|
pytest.fail("This is a failing test")
|
||||||
|
|
||||||
|
def test_bar(baz):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest("--maxfail=1")
|
||||||
|
result.stdout.fnmatch_lines(["*1 failed, 1 error*"])
|
||||||
|
|
Loading…
Reference in New Issue