From 6d45581910b7a7a6dc7d9d4670353e2cabd509fa Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 16 Jun 2026 13:59:33 -0400 Subject: [PATCH] Add autouse fixture to reset `_runtime_vars` per-test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `open_root_actor()` writes `_enable_tpts` (and friends) into the process-global `_state._runtime_vars` dict but nothing resets it on actor teardown. Under the in-proc `pytest` launchpad a uds-using test leaks `_enable_tpts=['uds']` into a sibling tcp test, tripping the `registry_addrs`×`enable_transports` proto-guard in `open_root_actor()` with a `ValueError`. New `_reset_runtime_vars` fixture snapshots + restores the dict around every test so no runtime-var state crosses a test boundary. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tractor/_testing/pytest.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tractor/_testing/pytest.py b/tractor/_testing/pytest.py index 37fc211e..0b2cc6f6 100644 --- a/tractor/_testing/pytest.py +++ b/tractor/_testing/pytest.py @@ -586,6 +586,32 @@ def alert_on_finish(): # - sway/i3-nag? +@pytest.fixture(autouse=True) +def _reset_runtime_vars(): + ''' + Per-test isolation of the process-global + `tractor.runtime._state._runtime_vars`. + + `open_root_actor()` writes `_enable_tpts` (and other runtime + vars) into this module-global dict, but nothing resets it on + actor teardown. Under the in-process `pytest` launchpad a + uds-using test therefore leaks `_enable_tpts=['uds']` into a + sibling tcp test, which then trips the + `registry_addrs`×`enable_transports` proto-guard in + `open_root_actor()` with a `ValueError`. Snapshot + restore + around every test so no runtime-var state crosses a test + boundary. + + ''' + from tractor.runtime import _state + snapshot: dict = dict(_state._runtime_vars) + try: + yield + finally: + _state._runtime_vars.clear() + _state._runtime_vars.update(snapshot) + + @pytest.fixture(scope='session') def debug_mode( request: pytest.FixtureRequest,