MCPcopy
hub / github.com/benoitc/gunicorn / docker_services

Function docker_services

tests/docker/asgi_framework_compat/conftest.py:93–138  ·  view source on GitHub ↗

Start Docker services for testing.

(docker_compose_file, request)

Source from the content-addressed store, hash-verified

91
92@pytest.fixture(scope="session")
93def docker_services(docker_compose_file, request):
94 """Start Docker services for testing."""
95 if request.config.getoption("--skip-docker-check"):
96 yield
97 return
98
99 # Check if containers are already running
100 all_healthy = True
101 for name, config in FRAMEWORKS.items():
102 url = f"http://{DOCKER_HOST}:{config['port']}"
103 try:
104 response = httpx.get(f"{url}/health", timeout=2.0)
105 if response.status_code != 200:
106 all_healthy = False
107 break
108 except (httpx.ConnectError, httpx.TimeoutException):
109 all_healthy = False
110 break
111
112 if all_healthy:
113 yield
114 return
115
116 # Start containers
117 compose_dir = os.path.dirname(docker_compose_file)
118 subprocess.run(
119 ["docker", "compose", "up", "-d", "--build"],
120 cwd=compose_dir,
121 check=True,
122 )
123
124 # Wait for all services to be healthy
125 for name, config in FRAMEWORKS.items():
126 url = f"http://{DOCKER_HOST}:{config['port']}"
127 if not wait_for_service(url):
128 pytest.fail(f"Service {name} failed to start")
129
130 yield
131
132 # Optionally stop containers after tests
133 if os.environ.get("CLEANUP_DOCKER", "0") == "1":
134 subprocess.run(
135 ["docker", "compose", "down"],
136 cwd=compose_dir,
137 check=True,
138 )
139
140
141@pytest.fixture(params=list(FRAMEWORKS.keys()))

Callers

nothing calls this directly

Calls 4

itemsMethod · 0.80
wait_for_serviceFunction · 0.70
getMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected