Add autouse fixture to reset `_runtime_vars` per-test

`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
trionics_start_or_cancel
Gud Boi 2026-06-16 13:59:33 -04:00
parent 6a7dea45bb
commit 6d45581910
1 changed files with 26 additions and 0 deletions

View File

@ -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,