1212
1313from omniload .target .clickhouse import ClickhouseDestination
1414from tests .util .common import get_testdata_path
15+ from tests .warehouse .manager import REMOTE_FILESYSTEM_SERVICES
1516from tests .warehouse .settings import DESTINATIONS , SOURCES
1617
1718logger = logging .getLogger (__name__ )
1819
1920
21+ def _explicit_test_targets (config ) -> list [Path ]:
22+ """Return explicit repo test paths from pytest's original invocation."""
23+ targets = []
24+ for arg in config .invocation_params .args :
25+ raw_path = arg .split ("::" , 1 )[0 ]
26+ if raw_path .startswith ("-" ):
27+ continue
28+ path = Path (raw_path )
29+ if not path .is_absolute ():
30+ normalized = raw_path .removeprefix ("./" )
31+ if normalized .split ("/" , 1 )[0 ] not in {"tests" , "examples" , "omniload" }:
32+ continue
33+ path = Path (config .rootpath ) / normalized
34+ targets .append (path .resolve ())
35+ return targets
36+
37+
38+ def _only_main_filesystem_tests (config ) -> bool :
39+ """Return whether every explicit pytest target is in main/filesystem."""
40+ filesystem_root = (Path (config .rootpath ) / "tests/main/filesystem" ).resolve ()
41+ targets = _explicit_test_targets (config )
42+ return bool (targets ) and all (
43+ target == filesystem_root or filesystem_root in target .parents
44+ for target in targets
45+ )
46+
47+
48+ def _remote_filesystem_tests_selected (config ) -> bool :
49+ """Return whether the invocation can collect the remote emulator test module."""
50+ remote_tests = (
51+ Path (config .rootpath ) / "tests/main/filesystem/test_remote_integration.py"
52+ ).resolve ()
53+ targets = _explicit_test_targets (config )
54+ if not targets :
55+ return True
56+ return any (
57+ target == remote_tests or target in remote_tests .parents for target in targets
58+ )
59+
60+
61+ def _all_managed_containers ():
62+ return (
63+ set (SOURCES .values ())
64+ | set (DESTINATIONS .values ())
65+ | set (REMOTE_FILESYSTEM_SERVICES .values ())
66+ )
67+
68+
69+ def _managed_containers (config ):
70+ containers = set ()
71+ if not _only_main_filesystem_tests (config ):
72+ containers |= set (SOURCES .values ()) | set (DESTINATIONS .values ())
73+ if _remote_filesystem_tests_selected (config ):
74+ containers |= set (REMOTE_FILESYSTEM_SERVICES .values ())
75+ return containers
76+
77+
2078def pytest_configure (config ):
2179 logging .getLogger ("urllib3.connectionpool" ).setLevel (logging .INFO )
2280 logging .getLogger ("testcontainers.core.waiting_utils" ).setLevel (logging .WARNING )
@@ -100,8 +158,10 @@ def testdata_path() -> Path:
100158
101159@pytest .fixture (scope = "session" , autouse = True )
102160def manage_containers (request , shared_directory ):
103- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
104- for container in unique_containers :
161+ # Set every lock directory on both controller and workers. Container boot is
162+ # still filtered below, but fixture polling must not depend on both processes
163+ # deriving exactly the same target set from their invocation arguments.
164+ for container in _all_managed_containers ():
105165 container .lock_dir = shared_directory # ty: ignore[invalid-assignment, unresolved-attribute, unused-ignore-comment]
106166
107167
@@ -111,8 +171,7 @@ def start_containers(config):
111171 if is_worker (config ):
112172 return
113173
114- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
115- unique_containers = [x for x in unique_containers if x is not None ]
174+ unique_containers = [x for x in _managed_containers (config ) if x is not None ]
116175
117176 for container in unique_containers :
118177 container .lock_dir = config .shared_directory # ty: ignore[invalid-assignment, unresolved-attribute, unused-ignore-comment]
@@ -164,8 +223,7 @@ def stop_containers(config):
164223 if not should_manage_containers :
165224 return
166225
167- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
168- unique_containers = [x for x in unique_containers if x is not None ]
226+ unique_containers = [x for x in _managed_containers (config ) if x is not None ]
169227
170228 for container in unique_containers :
171229 try :
0 commit comments