Skip to content

Commit 58cc54f

Browse files
committed
Fix integration reload isolation
1 parent 048d77c commit 58cc54f

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

tests/integration/core/test_runtime_migration.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"utils.opensearch_init",
3737
]
3838

39+
_RELOAD_PREFIXES = ("api.", "app.", "services.")
40+
41+
42+
def _purge_reloaded_modules() -> None:
43+
for mod in list(sys.modules):
44+
if mod in _RELOAD_MODULES or mod.startswith(_RELOAD_PREFIXES):
45+
sys.modules.pop(mod, None)
46+
3947

4048
@pytest_asyncio.fixture
4149
async def legacy_migration_workspace(tmp_path: Path, monkeypatch):
@@ -62,8 +70,7 @@ async def legacy_migration_workspace(tmp_path: Path, monkeypatch):
6270
from db.engine import dispose_engine as dispose_existing_engine
6371

6472
await dispose_existing_engine()
65-
for mod in _RELOAD_MODULES:
66-
sys.modules.pop(mod, None)
73+
_purge_reloaded_modules()
6774

6875
from config.config_manager import config_manager
6976
from db.engine import dispose_engine
@@ -110,8 +117,7 @@ async def legacy_migration_workspace(tmp_path: Path, monkeypatch):
110117
session_ownership_service.ownership_file = old_ownership_file
111118
session_ownership_service.ownership_data = old_ownership_data
112119
session_ownership_service._session_factory = old_ownership_session_factory
113-
for mod in _RELOAD_MODULES:
114-
sys.modules.pop(mod, None)
120+
_purge_reloaded_modules()
115121

116122

117123
def _write_legacy_files(*, config_dir: Path, data_dir: Path) -> None:

tests/integration/core/test_startup_ingest.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@
77

88
# Files to exclude from ingestion (should match src/main.py)
99
EXCLUDED_INGESTION_FILES = {"warmup_ocr.pdf"}
10+
_RELOAD_MODULES = [
11+
"api",
12+
"api.router",
13+
"api.connector_router",
14+
"app",
15+
"app.container",
16+
"app.factory",
17+
"app.lifespan",
18+
"app.routes",
19+
"app.routes.internal",
20+
"config.settings",
21+
"dependencies",
22+
"auth_middleware",
23+
"main",
24+
"services",
25+
"services.default_docs_service",
26+
"services.search_service",
27+
"services.startup_orchestrator",
28+
"utils.opensearch_init",
29+
]
30+
_RELOAD_PREFIXES = ("api.", "app.", "services.")
31+
32+
33+
def _purge_reloaded_modules() -> None:
34+
import sys
35+
36+
for mod in list(sys.modules):
37+
if mod in _RELOAD_MODULES or mod.startswith(_RELOAD_PREFIXES):
38+
sys.modules.pop(mod, None)
1039

1140

1241
async def wait_for_ready(client: httpx.AsyncClient, timeout_s: float = 30.0):
@@ -48,28 +77,7 @@ async def test_startup_ingest_creates_task(disable_langflow_ingest: bool):
4877
os.environ["GOOGLE_OAUTH_CLIENT_SECRET"] = ""
4978

5079
# Reload settings to pick up env for this test run
51-
import sys
52-
53-
for mod in [
54-
"api.router",
55-
"api.connector_router",
56-
"api",
57-
"app.container",
58-
"app.factory",
59-
"app.lifespan",
60-
"app.routes",
61-
"app.routes.internal",
62-
"config.settings",
63-
"dependencies",
64-
"auth_middleware",
65-
"main",
66-
"services",
67-
"services.default_docs_service",
68-
"services.search_service",
69-
"services.startup_orchestrator",
70-
"utils.opensearch_init",
71-
]:
72-
sys.modules.pop(mod, None)
80+
_purge_reloaded_modules()
7381

7482
from config.settings import clients, get_index_name
7583
from main import create_app

0 commit comments

Comments
 (0)