|
24 | 24 | from __future__ import annotations |
25 | 25 |
|
26 | 26 | import multiprocessing |
27 | | -import sys |
28 | | - |
29 | | -import fasteners |
30 | 27 |
|
31 | 28 | multiprocessing.set_start_method("spawn", force=True) |
32 | 29 |
|
|
38 | 35 | import pytest |
39 | 36 | import openml_sklearn |
40 | 37 |
|
41 | | -import time |
42 | | -import subprocess |
43 | | -import requests |
44 | 38 | import openml |
45 | 39 | from openml.testing import TestBase |
46 | 40 |
|
@@ -302,46 +296,18 @@ def with_test_cache(test_files_directory, request): |
302 | 296 | if tmp_cache.exists(): |
303 | 297 | shutil.rmtree(tmp_cache) |
304 | 298 |
|
305 | | -def _is_server_responding(): |
306 | | - """Check if the Docker API is already listening.""" |
307 | | - try: |
308 | | - requests.get("http://localhost:9001/api/v2/", timeout=1) |
309 | | - return True |
310 | | - except (requests.exceptions.ConnectionError, requests.exceptions.Timeout): |
311 | | - return False |
312 | | - |
313 | | -def _start_docker(): |
314 | | - """Logic to spin up the containers and wait for initialization.""" |
315 | | - subprocess.run(["docker", "compose", "up", "-d"], check=True, capture_output=True, text=True) |
316 | | - subprocess.run(["docker", "wait", "openml-test-setup-ci"], check=True) |
317 | | - |
318 | | -@pytest.fixture(scope="session", autouse=True) |
319 | | -def openml_docker_stack(tmp_path_factory, worker_id): |
320 | | - # Skip Docker setup in CI on Windows given docker images are for Linux |
321 | | - is_ci = os.environ.get("CI") == "true" |
322 | | - is_windows = sys.platform == "win32" or os.name == "nt" |
323 | | - |
324 | | - if is_ci and is_windows: |
325 | | - yield |
326 | | - return |
327 | | - |
328 | | - # For local development with single worker |
329 | | - if worker_id == "master": |
330 | | - _start_docker() |
331 | | - yield |
332 | | - subprocess.run(["docker", "compose", "down", "-v"], check=True) |
333 | | - return |
334 | | - |
335 | | - # For CI with multiple workers (xdist) |
336 | | - root_tmp_dir = tmp_path_factory.getbasetemp().parent |
337 | | - lock_file = root_tmp_dir / "docker_setup.lock" |
| 299 | +@pytest.fixture(scope="session") |
| 300 | +def openml_test_config(): |
| 301 | + """ |
| 302 | + Returns the URL for the test server. |
| 303 | + """ |
| 304 | + if os.environ.get("OPENML_TEST_SERVER") == "local": |
| 305 | + return { |
| 306 | + "v1": "http://localhost:9002/api/v1/", |
| 307 | + "v2": "http://localhost:9001/" |
| 308 | + } |
338 | 309 |
|
339 | | - lock = fasteners.InterProcessLock(str(lock_file)) |
340 | | - with lock: |
341 | | - if not _is_server_responding(): |
342 | | - _start_docker() |
343 | | - |
344 | | - yield |
| 310 | + raise ValueError("Use the environment variable OPENML_TEST_SERVER=local before running docker to run tests against a local OpenML server.") |
345 | 311 |
|
346 | 312 | @pytest.fixture |
347 | 313 | def static_cache_dir(): |
|
0 commit comments