From e4da9b26f609ef95a6d2a805ff1c572815a7f0fc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 20 Jul 2026 20:48:55 +0000 Subject: [PATCH] Make test_remote_policy.py self-contained test_refresh_remote and test_refresh_remote_retries_on_timeout only passed when an earlier test file had already set the global supervisor's policy token to "tok"; running the file standalone failed with PolicyAuthError. Add a fixture that sets the token and restores the previous value. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01DDSofWX5HwawsrwbN2nSXR --- tests/test_remote_policy.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/test_remote_policy.py b/tests/test_remote_policy.py index f8158b4..b6f3f2d 100644 --- a/tests/test_remote_policy.py +++ b/tests/test_remote_policy.py @@ -10,9 +10,22 @@ import pytest +import pyisolate import pyisolate.policy as policy +@pytest.fixture +def policy_token(): + # refresh_remote ends in Supervisor.reload_policy, which authorizes against + # the global supervisor's policy token. Set it here (and restore afterwards) + # so this file does not depend on an earlier test file having set it. + sup = pyisolate.supervisor._get_supervisor() + old = sup._policy_token + pyisolate.set_policy_token("tok") + yield "tok" + sup._policy_token = old + + class PolicyHandler(BaseHTTPRequestHandler): def do_GET(self): doc = "version: 0.1\n" @@ -25,7 +38,7 @@ def log_message(self, format, *args): # pragma: no cover - quiet test output return -def test_refresh_remote(tmp_path): +def test_refresh_remote(tmp_path, policy_token): addr = ("127.0.0.1", 0) httpd = HTTPServer(addr, PolicyHandler) port = httpd.server_address[1] @@ -66,7 +79,7 @@ def log_message(self, format, *args): # pragma: no cover - quiet test output return -def test_refresh_remote_retries_on_timeout(tmp_path): +def test_refresh_remote_retries_on_timeout(tmp_path, policy_token): addr = ("127.0.0.1", 0) httpd = ThreadingHTTPServer(addr, SlowFirstHandler) port = httpd.server_address[1]