From ab18cd7797536525c23b2ddae1a995fbbbeb559d Mon Sep 17 00:00:00 2001 From: anti Date: Sun, 10 May 2026 22:29:57 -0400 Subject: [PATCH] fix(live tests): replace deprecated event_loop fixture with loop_scope="module" on async fixtures --- tests/live/test_health_live.py | 13 +++---------- tests/live/test_mysql_backend_live.py | 2 +- tests/live/test_service_isolation_live.py | 13 +++---------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/tests/live/test_health_live.py b/tests/live/test_health_live.py index 1afe1d25..e6f8ba80 100644 --- a/tests/live/test_health_live.py +++ b/tests/live/test_health_live.py @@ -34,14 +34,7 @@ from sqlalchemy.pool import StaticPool # noqa: E402 import uuid as _uuid # noqa: E402 -@pytest.fixture(scope="module") -def event_loop(): - loop = asyncio.new_event_loop() - yield loop - loop.close() - - -@pytest.fixture(scope="module", autouse=True) +@pytest.fixture(scope="module", loop_scope="module", autouse=True) async def live_db(): """Spin up an in-memory SQLite for the live test module.""" engine = create_async_engine( @@ -75,7 +68,7 @@ async def live_db(): await engine.dispose() -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", loop_scope="module") async def live_client(live_db): async with httpx.AsyncClient( transport=httpx.ASGITransport(app=app), @@ -84,7 +77,7 @@ async def live_client(live_db): yield ac -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", loop_scope="module") async def token(live_client): resp = await live_client.post("/api/v1/auth/login", json={ "username": DECNET_ADMIN_USER, diff --git a/tests/live/test_mysql_backend_live.py b/tests/live/test_mysql_backend_live.py index fe798e7e..c571f575 100644 --- a/tests/live/test_mysql_backend_live.py +++ b/tests/live/test_mysql_backend_live.py @@ -74,7 +74,7 @@ def _url_with_db(server_url: str, db_name: str) -> str: return urlunparse(parsed._replace(path=f"/{db_name}")) -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", loop_scope="module") async def mysql_test_db_url(): """Create a per-worker throwaway database, yield its URL, drop it on teardown. diff --git a/tests/live/test_service_isolation_live.py b/tests/live/test_service_isolation_live.py index 07d1be3b..36349272 100644 --- a/tests/live/test_service_isolation_live.py +++ b/tests/live/test_service_isolation_live.py @@ -66,14 +66,7 @@ from sqlalchemy.pool import StaticPool # noqa: E402 # ─── Shared fixtures ──────────────────────────────────────────────────────── -@pytest.fixture(scope="module") -def event_loop(): - loop = asyncio.new_event_loop() - yield loop - loop.close() - - -@pytest.fixture(scope="module", autouse=True) +@pytest.fixture(scope="module", loop_scope="module", autouse=True) async def live_db(): """Real in-memory SQLite — shared across this module.""" engine = create_async_engine( @@ -111,7 +104,7 @@ async def live_db(): await engine.dispose() -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", loop_scope="module") async def live_client(live_db): async with httpx.AsyncClient( transport=httpx.ASGITransport(app=app), @@ -120,7 +113,7 @@ async def live_client(live_db): yield ac -@pytest.fixture(scope="module") +@pytest.fixture(scope="module", loop_scope="module") async def token(live_client): resp = await live_client.post( "/api/v1/auth/login",