Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compatibility with pytest 8.2 by restoring deleted finalizers #278

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading