fix(test): restore decnet.cli in sys.modules via monkeypatch to prevent agent-mode app stripping from leaking into subsequent tests
This commit is contained in:
@@ -79,10 +79,10 @@ def test_defence_in_depth_direct_call_fails_in_agent_mode(monkeypatch):
|
|||||||
monkeypatch.setenv("DECNET_MODE", "agent")
|
monkeypatch.setenv("DECNET_MODE", "agent")
|
||||||
monkeypatch.setenv("DECNET_DISALLOW_MASTER", "true")
|
monkeypatch.setenv("DECNET_DISALLOW_MASTER", "true")
|
||||||
# Re-import cli so the module-level gate re-runs (harmless here;
|
# Re-import cli so the module-level gate re-runs (harmless here;
|
||||||
# we're exercising the in-function guard).
|
# we're exercising the in-function guard). Use monkeypatch.delitem so
|
||||||
for mod in list(sys.modules):
|
# the original cached module is restored after the test and subsequent
|
||||||
if mod == "decnet.cli":
|
# tests don't see the agent-mode-stripped app singleton.
|
||||||
sys.modules.pop(mod)
|
monkeypatch.delitem(sys.modules, "decnet.cli", raising=False)
|
||||||
from decnet.cli import _require_master_mode
|
from decnet.cli import _require_master_mode
|
||||||
import typer
|
import typer
|
||||||
with pytest.raises(typer.Exit):
|
with pytest.raises(typer.Exit):
|
||||||
|
|||||||
Reference in New Issue
Block a user