Skip to content

Commit

Permalink
fix compatibility with pytest 8.2 by restoring deleted finalizers (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Howitz <[email protected]>
  • Loading branch information
jakkdl and icemac authored Nov 5, 2024
1 parent a53b934 commit 17e7b23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
14.1 (unreleased)
-----------------

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


14.0 (2024-03-13)
Expand Down
12 changes: 11 additions & 1 deletion src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ def _get(self, i: str, k: str) -> int:
return int(self._sock_recv(self.sock))


suspended_finalizers = {}


def pytest_runtest_teardown(item, nextitem):
reruns = get_reruns_count(item)
if reruns is None:
Expand All @@ -490,13 +493,20 @@ def pytest_runtest_teardown(item, nextitem):
and any(_test_failed_statuses.values())
and not any(item._terminal_errors.values())
):
# clean cashed results from any level of setups
# clean cached results from any level of setups
_remove_cached_results_from_failed_fixtures(item)

if item in item.session._setupstate.stack:
for key in list(item.session._setupstate.stack.keys()):
if key != item:
# only the first finalizer contains the correct teardowns
if key not in suspended_finalizers:
suspended_finalizers[key] = item.session._setupstate.stack[key]
del item.session._setupstate.stack[key]
else:
# restore suspended finalizers
item.session._setupstate.stack.update(suspended_finalizers)
suspended_finalizers.clear()


@pytest.hookimpl(hookwrapper=True)
Expand Down

0 comments on commit 17e7b23

Please sign in to comment.