From 9f3efd952b3356bccf1506ce771ab9971cea5257 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 11:31:27 +0000 Subject: [PATCH 1/2] fix: resolve asyncio event loop error in backend auth tests Convert sync client fixture to async fixture, use pytest-asyncio auto mode, and properly manage AsyncClient lifecycle with async context manager. --- web_strategy_studio/backend/pyproject.toml | 1 + web_strategy_studio/backend/tests/test_auth.py | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/web_strategy_studio/backend/pyproject.toml b/web_strategy_studio/backend/pyproject.toml index 3f1a3eb..bed694b 100644 --- a/web_strategy_studio/backend/pyproject.toml +++ b/web_strategy_studio/backend/pyproject.toml @@ -38,6 +38,7 @@ studio_api = ["data/*.json"] [tool.pytest.ini_options] testpaths = ["tests"] python_files = ["test_*.py"] +asyncio_mode = "auto" [tool.ruff] line-length = 100 diff --git a/web_strategy_studio/backend/tests/test_auth.py b/web_strategy_studio/backend/tests/test_auth.py index 2ab1759..ca7b033 100644 --- a/web_strategy_studio/backend/tests/test_auth.py +++ b/web_strategy_studio/backend/tests/test_auth.py @@ -66,7 +66,7 @@ class TestAuthEndpoints: """Test the /auth endpoints using httpx + FastAPI TestClient.""" @pytest.fixture - def client(self, tmp_path): + async def client(self, tmp_path): """Create a test client with a fresh SQLite DB in tmp_path.""" from httpx import ASGITransport, AsyncClient @@ -84,18 +84,14 @@ def client(self, tmp_path): new_engine, class_=db_mod.AsyncSession, expire_on_commit=False ) - import asyncio - - async def setup_db(): - async with new_engine.begin() as conn: - await conn.run_sync(Base.metadata.create_all) - - asyncio.get_event_loop().run_until_complete(setup_db()) + async with new_engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) from studio_api.app import app transport = ASGITransport(app=app) - return AsyncClient(transport=transport, base_url="http://test") + async with AsyncClient(transport=transport, base_url="http://test") as ac: + yield ac @pytest.mark.asyncio async def test_register_returns_token(self, client): From d4c176bd8af24c9dfe5f84c7cb6b362ed1cbbb79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 11:32:09 +0000 Subject: [PATCH 2/2] fix: add engine disposal to prevent resource leaks in auth tests --- web_strategy_studio/backend/tests/test_auth.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_strategy_studio/backend/tests/test_auth.py b/web_strategy_studio/backend/tests/test_auth.py index ca7b033..b6a09fa 100644 --- a/web_strategy_studio/backend/tests/test_auth.py +++ b/web_strategy_studio/backend/tests/test_auth.py @@ -93,6 +93,8 @@ async def client(self, tmp_path): async with AsyncClient(transport=transport, base_url="http://test") as ac: yield ac + await new_engine.dispose() + @pytest.mark.asyncio async def test_register_returns_token(self, client): resp = await client.post(