diff --git a/CHANGES.rst b/CHANGES.rst index 6e3dca6..68783aa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 14.1 (unreleased) ----------------- -- Nothing changed yet. +- Fix compatibility with pytest 8.2. + (`#267 `_) 14.0 (2024-03-13) diff --git a/src/pytest_rerunfailures.py b/src/pytest_rerunfailures.py index 75afc48..d11e1bc 100644 --- a/src/pytest_rerunfailures.py +++ b/src/pytest_rerunfailures.py @@ -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: @@ -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)