PR feedback: Move changing of nextitem to runtestprotocol and also check for shouldstop

This commit is contained in:
Ben Brown 2024-01-02 11:02:46 -05:00 committed by Ran Benita
parent 7176470866
commit f90dc391e7
1 changed files with 6 additions and 3 deletions

View File

@ -131,6 +131,12 @@ def runtestprotocol(
show_test_item(item) show_test_item(item)
if not item.config.getoption("setuponly", False): if not item.config.getoption("setuponly", False):
reports.append(call_and_report(item, "call", log)) 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)) reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
# After all teardown hooks have been called # After all teardown hooks have been called
# want funcargs and request info to go away. # 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: 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)