Skip to content

Commit 1b00a2f

Browse files
authored
Merge pull request #12025 from pytest-dev/backport-12022-to-8.0.x
[8.0.x] Revert "Fix teardown error reporting when `--maxfail=1` (#11721)"
2 parents 8a8eed6 + ff2f66d commit 1b00a2f

File tree

4 files changed

+3
-54
lines changed

4 files changed

+3
-54
lines changed

Diff for: 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.

Diff for: 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.

Diff for: 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.

Diff for: testing/test_runner.py

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

0 commit comments

Comments
 (0)