Skip to content

Commit 25b4e34

Browse files
committed
no wild creation of event loops in tests
1 parent a2dae07 commit 25b4e34

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

packages/pytest-simcore/src/pytest_simcore/docker_swarm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ def _make_dask_sidecar_certificates(simcore_service_folder: Path) -> None:
246246

247247

248248
@pytest.fixture(scope="module")
249-
def docker_stack(
249+
async def docker_stack(
250250
osparc_simcore_services_dir: Path,
251251
docker_swarm: None,
252252
docker_client: docker.client.DockerClient,
253253
core_docker_compose_file: Path,
254254
ops_docker_compose_file: Path,
255255
keep_docker_up: bool,
256256
env_vars_for_docker_compose: EnvVarsDict,
257-
) -> Iterator[dict]:
257+
) -> AsyncIterator[dict]:
258258
"""deploys core and ops stacks and returns as soon as all are running"""
259259

260260
# WARNING: keep prefix "pytest-" in stack names
@@ -313,7 +313,7 @@ async def _check_all_services_are_running():
313313

314314
assert not pending, f"some service did not start correctly [{pending}]"
315315

316-
asyncio.run(_check_all_services_are_running())
316+
await _check_all_services_are_running()
317317

318318
finally:
319319
_fetch_and_print_services(docker_client, "[BEFORE TEST]")

packages/pytest-simcore/src/pytest_simcore/simcore_services.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ async def wait_till_service_healthy(service_name: str, endpoint: URL):
9090
reraise=True,
9191
):
9292
with attempt:
93-
async with aiohttp.ClientSession(
94-
timeout=_ONE_SEC_TIMEOUT
95-
) as session, session.get(endpoint) as response:
93+
async with (
94+
aiohttp.ClientSession(timeout=_ONE_SEC_TIMEOUT) as session,
95+
session.get(endpoint) as response,
96+
):
9697
# NOTE: Health-check endpoint require only a status code 200
9798
# (see e.g. services/web/server/docker/healthcheck.py)
9899
# regardless of the payload content
@@ -164,7 +165,7 @@ def services_endpoint(
164165
return services_endpoint
165166

166167

167-
def _wait_for_services_ready(services_endpoint: dict[str, URL]) -> None:
168+
async def _wait_for_services_ready(services_endpoint: dict[str, URL]) -> None:
168169
# Compose and log healthcheck url entpoints
169170

170171
health_endpoints = [
@@ -188,14 +189,14 @@ async def _check_all_services_are_healthy():
188189
)
189190

190191
# check ready
191-
asyncio.run(_check_all_services_are_healthy())
192+
await _check_all_services_are_healthy()
192193

193194

194195
@pytest.fixture
195-
def simcore_services_ready(
196+
async def simcore_services_ready(
196197
services_endpoint: dict[str, URL], monkeypatch: pytest.MonkeyPatch
197198
) -> None:
198-
_wait_for_services_ready(services_endpoint)
199+
await _wait_for_services_ready(services_endpoint)
199200
# patches environment variables with right host/port per service
200201
for service, endpoint in services_endpoint.items():
201202
env_prefix = service.upper().replace("-", "_")
@@ -225,16 +226,15 @@ def _monkeypatch_module(request: pytest.FixtureRequest) -> Iterator[pytest.Monke
225226

226227

227228
@pytest.fixture(scope="module")
228-
def simcore_services_ready_module(
229+
async def simcore_services_ready_module(
229230
services_endpoint: dict[str, URL], _monkeypatch_module: pytest.MonkeyPatch
230231
) -> None:
231232
warnings.warn(
232-
"This fixture uses deprecated monkeypatch_module fixture"
233-
"Please do NOT use it!",
233+
"This fixture uses deprecated monkeypatch_module fixturePlease do NOT use it!",
234234
DeprecationWarning,
235235
stacklevel=1,
236236
)
237-
_wait_for_services_ready(services_endpoint)
237+
await _wait_for_services_ready(services_endpoint)
238238
# patches environment variables with right host/port per service
239239
for service, endpoint in services_endpoint.items():
240240
env_prefix = service.upper().replace("-", "_")

0 commit comments

Comments
 (0)