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)