diff --git a/tests/test_issue_682_starlette_httpx2.py b/tests/test_issue_682_starlette_httpx2.py index 02feb2d..ff49c8e 100644 --- a/tests/test_issue_682_starlette_httpx2.py +++ b/tests/test_issue_682_starlette_httpx2.py @@ -9,7 +9,6 @@ import warnings from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -sys.path.insert(0, str(Path(__file__).resolve().parent)) class TestHttpx2Installed(unittest.TestCase): @@ -21,32 +20,39 @@ class TestHttpx2Installed(unittest.TestCase): class TestNoStarletteTestClientDeprecation(unittest.TestCase): def test_starlette_testclient_import_does_not_warn(self) -> None: # Force a fresh import path so a previous httpx-fallback warning cannot - # hide a regression after httpx2 is present. - for name in list(sys.modules): - if name == "starlette.testclient" or name.startswith("starlette.testclient."): + # hide a regression after httpx2 is present. Restore sys.modules afterwards. + saved = { + name: sys.modules[name] + for name in list(sys.modules) + if name == "starlette.testclient" or name.startswith("starlette.testclient.") + } + try: + for name in list(saved): del sys.modules[name] - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - import starlette.testclient as testclient # noqa: F401 + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + import starlette.testclient as testclient # noqa: F401 - dep = [ - w - for w in caught - if "httpx" in str(w.message).lower() - and "deprecated" in str(w.message).lower() - ] - self.assertEqual( - dep, - [], - f"expected no Starlette httpx deprecation warning; got: " - f"{[str(w.message) for w in dep]}", - ) + dep = [ + w + for w in caught + if "httpx" in str(w.message).lower() + and "deprecated" in str(w.message).lower() + ] + self.assertEqual( + dep, + [], + f"expected no Starlette httpx deprecation warning; got: " + f"{[str(w.message) for w in dep]}", + ) + finally: + sys.modules.update(saved) def test_canonical_webui_testclient_import(self) -> None: with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") - from webui_testclient import TestClient + from tests.webui_testclient import TestClient from webui.app import create_app client = TestClient(create_app()) diff --git a/tests/test_webui_analytics.py b/tests/test_webui_analytics.py index d7612cb..560c2d9 100644 --- a/tests/test_webui_analytics.py +++ b/tests/test_webui_analytics.py @@ -5,7 +5,7 @@ from __future__ import annotations import os import tempfile import unittest -from webui_testclient import TestClient +from tests.webui_testclient import TestClient import control_plane_db from webui.analytics_loader import ( diff --git a/tests/test_webui_audit.py b/tests/test_webui_audit.py index d636577..f6e33ad 100644 --- a/tests/test_webui_audit.py +++ b/tests/test_webui_audit.py @@ -5,7 +5,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.audit_validator import audit_report, infer_task_kind diff --git a/tests/test_webui_console_authz_audit.py b/tests/test_webui_console_authz_audit.py index 0545be3..79a361f 100644 --- a/tests/test_webui_console_authz_audit.py +++ b/tests/test_webui_console_authz_audit.py @@ -23,7 +23,7 @@ import sys import tempfile import unittest -from webui_testclient import TestClient +from tests.webui_testclient import TestClient sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) diff --git a/tests/test_webui_deployment_boundary.py b/tests/test_webui_deployment_boundary.py index b9b543d..d29ee26 100644 --- a/tests/test_webui_deployment_boundary.py +++ b/tests/test_webui_deployment_boundary.py @@ -7,7 +7,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.deployment_boundary import ( diff --git a/tests/test_webui_gated_actions.py b/tests/test_webui_gated_actions.py index 0630d70..1aa3e2b 100644 --- a/tests/test_webui_gated_actions.py +++ b/tests/test_webui_gated_actions.py @@ -6,7 +6,7 @@ from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from task_capability_map import TASK_CAPABILITY_MAP from webui.app import create_app diff --git a/tests/test_webui_inventory.py b/tests/test_webui_inventory.py index 3c299ce..fbca984 100644 --- a/tests/test_webui_inventory.py +++ b/tests/test_webui_inventory.py @@ -15,7 +15,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient import control_plane_db from webui.app import create_app diff --git a/tests/test_webui_lease_visibility.py b/tests/test_webui_lease_visibility.py index cceb395..ccb6da4 100644 --- a/tests/test_webui_lease_visibility.py +++ b/tests/test_webui_lease_visibility.py @@ -5,7 +5,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.lease_loader import ( diff --git a/tests/test_webui_mvp_suite.py b/tests/test_webui_mvp_suite.py index afbb3ab..0847eb9 100644 --- a/tests/test_webui_mvp_suite.py +++ b/tests/test_webui_mvp_suite.py @@ -9,7 +9,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from starlette.routing import Route from webui.app import create_app diff --git a/tests/test_webui_project_registry.py b/tests/test_webui_project_registry.py index bde5364..244a6e2 100644 --- a/tests/test_webui_project_registry.py +++ b/tests/test_webui_project_registry.py @@ -7,7 +7,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.project_registry import ( diff --git a/tests/test_webui_prompt_library.py b/tests/test_webui_prompt_library.py index f8c5f9c..c354273 100644 --- a/tests/test_webui_prompt_library.py +++ b/tests/test_webui_prompt_library.py @@ -6,7 +6,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.prompt_library import find_prompt, library_to_dict, load_prompt_library, prompt_to_dict diff --git a/tests/test_webui_queue_dashboard.py b/tests/test_webui_queue_dashboard.py index c338327..8c0c31a 100644 --- a/tests/test_webui_queue_dashboard.py +++ b/tests/test_webui_queue_dashboard.py @@ -7,7 +7,7 @@ from unittest import mock sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.queue_loader import ( diff --git a/tests/test_webui_runtime_health.py b/tests/test_webui_runtime_health.py index 410c99b..c775ae8 100644 --- a/tests/test_webui_runtime_health.py +++ b/tests/test_webui_runtime_health.py @@ -6,7 +6,7 @@ from unittest import mock sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.runtime_health import _role_kind, load_runtime_snapshot, snapshot_to_dict diff --git a/tests/test_webui_shell.py b/tests/test_webui_shell.py index 23ac384..57829c7 100644 --- a/tests/test_webui_shell.py +++ b/tests/test_webui_shell.py @@ -6,7 +6,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from starlette.routing import Route -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui import layout from webui.app import create_app diff --git a/tests/test_webui_skeleton.py b/tests/test_webui_skeleton.py index 6b74daf..de8275a 100644 --- a/tests/test_webui_skeleton.py +++ b/tests/test_webui_skeleton.py @@ -5,7 +5,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app diff --git a/tests/test_webui_system_health.py b/tests/test_webui_system_health.py index c84b341..151e715 100644 --- a/tests/test_webui_system_health.py +++ b/tests/test_webui_system_health.py @@ -16,7 +16,7 @@ from unittest import mock sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient import control_plane_db from webui.app import create_app diff --git a/tests/test_webui_system_health_dashboard.py b/tests/test_webui_system_health_dashboard.py index f96ece5..fad5baa 100644 --- a/tests/test_webui_system_health_dashboard.py +++ b/tests/test_webui_system_health_dashboard.py @@ -11,7 +11,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.deployment_boundary import scan_text_for_client_secrets diff --git a/tests/test_webui_timeline.py b/tests/test_webui_timeline.py index f1f486f..d5fcfb0 100644 --- a/tests/test_webui_timeline.py +++ b/tests/test_webui_timeline.py @@ -13,7 +13,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient import control_plane_db from canonical_thread_handoff import ( diff --git a/tests/test_webui_worktree_hygiene.py b/tests/test_webui_worktree_hygiene.py index 6adf107..519e010 100644 --- a/tests/test_webui_worktree_hygiene.py +++ b/tests/test_webui_worktree_hygiene.py @@ -7,7 +7,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from webui_testclient import TestClient +from tests.webui_testclient import TestClient from webui.app import create_app from webui.worktree_scanner import (