diff --git a/tests/unit/backends/test_cachekitio_transport_error_frames.py b/tests/unit/backends/test_cachekitio_transport_error_frames.py index 911829a4..b484bfcc 100644 --- a/tests/unit/backends/test_cachekitio_transport_error_frames.py +++ b/tests/unit/backends/test_cachekitio_transport_error_frames.py @@ -386,17 +386,15 @@ def classify(exc: BaseException, **kwargs: object) -> None: def test_interrupt_while_dropping_a_transport_failures_tracebacks_holds_no_exception(monkeypatch: pytest.MonkeyPatch) -> None: - """An interrupt that lands in ``_send``'s walk over a transport failure's chain, the error already built.""" + """An interrupt that lands in ``_send``'s walk over a transport failure's chain, the error already built. + + Only the transport handler's walk is patched: the interrupt branch uses the shared module's own walk. + """ walk = backend_module._raised_during_request - walks: list[BaseException] = [] def interrupted(exc: BaseException, handled_before: BaseException | None) -> Iterator[BaseException]: - walks.append(exc) - chain = walk(exc, handled_before) - yield next(chain) - if len(walks) == 1: # the transport handler's walk, not the interrupt branch's - raise KeyboardInterrupt - yield from chain + yield next(walk(exc, handled_before)) + raise KeyboardInterrupt monkeypatch.setattr(backend_module, "_raised_during_request", interrupted) backend = _faked(monkeypatch, lambda method, url, **kwargs: _make_request()) diff --git a/tests/unit/test_context_leak_regression.py b/tests/unit/test_context_leak_regression.py index 05e12aba..26528abb 100644 --- a/tests/unit/test_context_leak_regression.py +++ b/tests/unit/test_context_leak_regression.py @@ -36,7 +36,7 @@ def _isolated_stats_context(): """Start each test with no stats context and restore the outer one after it. - A leak stays set in the pytest thread's context, so without this one leaking + A leak stays set in the pytest thread's context, so without it, one leaking test would also fail every later test here that checks for None, and the failure would point at the wrong test. """ diff --git a/tests/unit/test_key_rotation_keyring.py b/tests/unit/test_key_rotation_keyring.py index 47029bd7..6be57b6f 100644 --- a/tests/unit/test_key_rotation_keyring.py +++ b/tests/unit/test_key_rotation_keyring.py @@ -1141,8 +1141,7 @@ async def test_l2_read_raises_without_running_or_counting(self, monkeypatch, liv for _ in range(3): with pytest.raises(KeyringConfigurationError, match="Keyring configuration invalid"): await _call(fn, 1) - # The sync wrapper has no outer `finally`: a raising exit that skips the - # stats reset leaks this call's stats into the caller's context. + # Every exit, this raise included, must restore the caller's stats context. assert get_current_function_stats() is None assert runs == []