Skip to content

Commit 00d9640

Browse files
committed
Revert "Fix teardown error reporting when --maxfail=1 (pytest-dev#11721)"
Fix pytest-dev#12021. Reopens pytest-dev#11706. This reverts commit 12b9bd5. This change caused a bad regression in pytest-xdist: pytest-dev/pytest-xdist#1024 pytest-xdist necessarily has special handling of `--maxfail` and session fixture teardown get executed multiple times with the change. Since I'm not sure how to adapt pytest-xdist myself, revert for now. I kept the sticky `shouldstop`/`shouldfail` changes as they are good ideas regardless I think.
1 parent 691d8fc commit 00d9640

File tree

4 files changed

+3
-54
lines changed

4 files changed

+3
-54
lines changed

changelog/12021.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reverted a fix to `--maxfail` handling in pytest 8.0.0 because it caused a regression in pytest-xdist whereby session fixture teardowns may get executed multiple times when the max-fails is reached.

doc/en/changelog.rst

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Bug Fixes
8585

8686
- `#11706 <https://github.com/pytest-dev/pytest/issues/11706>`_: Fix reporting of teardown errors in higher-scoped fixtures when using `--maxfail` or `--stepwise`.
8787

88+
NOTE: This change was reverted in pytest 8.0.2 to fix a `regression <https://github.com/pytest-dev/pytest-xdist/issues/1024>`_ it caused in pytest-xdist.
89+
8890

8991
- `#11758 <https://github.com/pytest-dev/pytest/issues/11758>`_: Fixed ``IndexError: string index out of range`` crash in ``if highlighted[-1] == "\n" and source[-1] != "\n"``.
9092
This bug was introduced in pytest 8.0.0rc1.

src/_pytest/runner.py

-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ def runtestprotocol(
132132
show_test_item(item)
133133
if not item.config.getoption("setuponly", False):
134134
reports.append(call_and_report(item, "call", log))
135-
# If the session is about to fail or stop, teardown everything - this is
136-
# necessary to correctly report fixture teardown errors (see #11706)
137-
if item.session.shouldfail or item.session.shouldstop:
138-
nextitem = None
139135
reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
140136
# After all teardown hooks have been called
141137
# want funcargs and request info to go away.

testing/test_runner.py

-50
Original file line numberDiff line numberDiff line change
@@ -1089,53 +1089,3 @@ def func() -> None:
10891089
with pytest.raises(TypeError) as excinfo:
10901090
OutcomeException(func) # type: ignore
10911091
assert str(excinfo.value) == expected
1092-
1093-
1094-
def test_teardown_session_failed(pytester: Pytester) -> None:
1095-
"""Test that higher-scoped fixture teardowns run in the context of the last
1096-
item after the test session bails early due to --maxfail.
1097-
1098-
Regression test for #11706.
1099-
"""
1100-
pytester.makepyfile(
1101-
"""
1102-
import pytest
1103-
1104-
@pytest.fixture(scope="module")
1105-
def baz():
1106-
yield
1107-
pytest.fail("This is a failing teardown")
1108-
1109-
def test_foo(baz):
1110-
pytest.fail("This is a failing test")
1111-
1112-
def test_bar(): pass
1113-
"""
1114-
)
1115-
result = pytester.runpytest("--maxfail=1")
1116-
result.assert_outcomes(failed=1, errors=1)
1117-
1118-
1119-
def test_teardown_session_stopped(pytester: Pytester) -> None:
1120-
"""Test that higher-scoped fixture teardowns run in the context of the last
1121-
item after the test session bails early due to --stepwise.
1122-
1123-
Regression test for #11706.
1124-
"""
1125-
pytester.makepyfile(
1126-
"""
1127-
import pytest
1128-
1129-
@pytest.fixture(scope="module")
1130-
def baz():
1131-
yield
1132-
pytest.fail("This is a failing teardown")
1133-
1134-
def test_foo(baz):
1135-
pytest.fail("This is a failing test")
1136-
1137-
def test_bar(): pass
1138-
"""
1139-
)
1140-
result = pytester.runpytest("--stepwise")
1141-
result.assert_outcomes(failed=1, errors=1)

0 commit comments

Comments
 (0)