Skip to content

Commit 17e7b23

Browse files
jakkdlicemac
andauthored
fix compatibility with pytest 8.2 by restoring deleted finalizers (#278)
Co-authored-by: Michael Howitz <[email protected]>
1 parent a53b934 commit 17e7b23

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGES.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Changelog
44
14.1 (unreleased)
55
-----------------
66

7-
- Nothing changed yet.
7+
- Fix compatibility with pytest 8.2.
8+
(`#267 <https://github.com/pytest-dev/pytest-rerunfailures/issues/267>`_)
89

910

1011
14.0 (2024-03-13)

src/pytest_rerunfailures.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ def _get(self, i: str, k: str) -> int:
468468
return int(self._sock_recv(self.sock))
469469

470470

471+
suspended_finalizers = {}
472+
473+
471474
def pytest_runtest_teardown(item, nextitem):
472475
reruns = get_reruns_count(item)
473476
if reruns is None:
@@ -490,13 +493,20 @@ def pytest_runtest_teardown(item, nextitem):
490493
and any(_test_failed_statuses.values())
491494
and not any(item._terminal_errors.values())
492495
):
493-
# clean cashed results from any level of setups
496+
# clean cached results from any level of setups
494497
_remove_cached_results_from_failed_fixtures(item)
495498

496499
if item in item.session._setupstate.stack:
497500
for key in list(item.session._setupstate.stack.keys()):
498501
if key != item:
502+
# only the first finalizer contains the correct teardowns
503+
if key not in suspended_finalizers:
504+
suspended_finalizers[key] = item.session._setupstate.stack[key]
499505
del item.session._setupstate.stack[key]
506+
else:
507+
# restore suspended finalizers
508+
item.session._setupstate.stack.update(suspended_finalizers)
509+
suspended_finalizers.clear()
500510

501511

502512
@pytest.hookimpl(hookwrapper=True)

0 commit comments

Comments
 (0)