From f90dc391e792f90070f0c28ef528474e76ec47e0 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 2 Jan 2024 11:02:46 -0500 Subject: [PATCH] PR feedback: Move changing of nextitem to runtestprotocol and also check for shouldstop --- src/_pytest/runner.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 6dd8e6c40..7ecc5bbeb 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -131,6 +131,12 @@ def runtestprotocol( show_test_item(item) if not item.config.getoption("setuponly", False): reports.append(call_and_report(item, "call", log)) + + # If the session is about to fail or stop, teardown everything - this is + # necessary to correctly report fixture teardown errors (see #11706) + if item.session.shouldfail or item.session.shouldstop: + nextitem = None + reports.append(call_and_report(item, "teardown", log, nextitem=nextitem)) # After all teardown hooks have been called # want funcargs and request info to go away. @@ -179,9 +185,6 @@ def pytest_runtest_call(item: Item) -> None: def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None: _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) _update_current_test_var(item, None)