1212
1313from omniload .target .clickhouse import ClickhouseDestination
1414from tests .util .common import get_testdata_path
15+ from tests .warehouse .manager import get_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+ if _integration_deselected (config ):
51+ return False
52+ remote_tests = (
53+ Path (config .rootpath ) / "tests/main/filesystem/test_remote_integration.py"
54+ ).resolve ()
55+ targets = _explicit_test_targets (config )
56+ if not targets :
57+ return True
58+ return any (
59+ target == remote_tests or target in remote_tests .parents for target in targets
60+ )
61+
62+
63+ def _all_managed_containers (config ):
64+ containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
65+ if _remote_filesystem_tests_selected (config ):
66+ containers |= set (get_remote_filesystem_services ().values ())
67+ return containers
68+
69+
70+ def _managed_containers (config ):
71+ containers = set ()
72+ if not _only_main_filesystem_tests (config ):
73+ containers |= set (SOURCES .values ()) | set (DESTINATIONS .values ())
74+ if _remote_filesystem_tests_selected (config ):
75+ containers |= set (get_remote_filesystem_services ().values ())
76+ return containers
77+
78+
2079def pytest_configure (config ):
2180 logging .getLogger ("urllib3.connectionpool" ).setLevel (logging .INFO )
2281 logging .getLogger ("testcontainers.core.waiting_utils" ).setLevel (logging .WARNING )
@@ -100,8 +159,10 @@ def testdata_path() -> Path:
100159
101160@pytest .fixture (scope = "session" , autouse = True )
102161def manage_containers (request , shared_directory ):
103- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
104- for container in unique_containers :
162+ # Set every lock directory on both controller and workers. Container boot is
163+ # still filtered below, but fixture polling must not depend on both processes
164+ # deriving exactly the same target set from their invocation arguments.
165+ for container in _all_managed_containers (request .config ):
105166 container .lock_dir = shared_directory # ty: ignore[invalid-assignment, unresolved-attribute, unused-ignore-comment]
106167
107168
@@ -111,8 +172,7 @@ def start_containers(config):
111172 if is_worker (config ):
112173 return
113174
114- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
115- unique_containers = [x for x in unique_containers if x is not None ]
175+ unique_containers = [x for x in _managed_containers (config ) if x is not None ]
116176
117177 for container in unique_containers :
118178 container .lock_dir = config .shared_directory # ty: ignore[invalid-assignment, unresolved-attribute, unused-ignore-comment]
@@ -164,8 +224,7 @@ def stop_containers(config):
164224 if not should_manage_containers :
165225 return
166226
167- unique_containers = set (SOURCES .values ()) | set (DESTINATIONS .values ())
168- unique_containers = [x for x in unique_containers if x is not None ]
227+ unique_containers = [x for x in _managed_containers (config ) if x is not None ]
169228
170229 for container in unique_containers :
171230 try :
0 commit comments