From 61d5cefe80ab817faad4a274413aa1b3d26fbed1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Mar 2026 00:03:46 +0000 Subject: [PATCH] fix: use module scope for e2e fixtures (more reliable than session) --- pyproject.toml | 2 +- tests/conftest.py | 22 ---------------------- tests/e2e/conftest.py | 8 ++++---- 3 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 tests/conftest.py diff --git a/pyproject.toml b/pyproject.toml index e478768..8615426 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,7 +89,7 @@ line-ending = "auto" [tool.pytest.ini_options] asyncio_mode = "auto" -asyncio_default_fixture_loop_scope = "session" +asyncio_default_fixture_loop_scope = "module" testpaths = ["tests"] addopts = "-v --tb=short" diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index eab1ec3..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Root conftest for all tests. - -Configures pytest-asyncio to use session-scoped event loop. -""" - -import asyncio - -import pytest - - -@pytest.fixture(scope="session") -def event_loop(): - """ - Create session-scoped event loop. - - This ensures all async fixtures use the SAME event loop - across all test files in the session. - """ - loop = asyncio.get_event_loop_policy().new_event_loop() - yield loop - loop.close() diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index ae8215c..03c1532 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -37,10 +37,10 @@ def require_credentials(kwork_credentials): return kwork_credentials -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") async def e2e_client(require_credentials): """ - E2E клиент - логинится ОДИН РАЗ для всех тестов сессии. + E2E клиент - логинится ОДИН РАЗ для всех тестов в модуле. Используется во всех тестах кроме test_auth.py (там тестируем сам логин). """ @@ -52,12 +52,12 @@ async def e2e_client(require_credentials): await client.close() -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") async def catalog_kwork_id(e2e_client): """ Получить ID первого кворка из каталога. - Выполняется ОДИН РАЗ в начале сессии и переиспользуется. + Выполняется ОДИН РАЗ в начале модуля и переиспользуется. """ catalog = await e2e_client.catalog.get_list(page=1) if len(catalog.kworks) > 0: