fix: use module scope for e2e fixtures (more reliable than session)

This commit is contained in:
root 2026-03-30 00:03:46 +00:00
parent 54f7a2bdd6
commit 61d5cefe80
3 changed files with 5 additions and 27 deletions

View File

@ -89,7 +89,7 @@ line-ending = "auto"
[tool.pytest.ini_options] [tool.pytest.ini_options]
asyncio_mode = "auto" asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "session" asyncio_default_fixture_loop_scope = "module"
testpaths = ["tests"] testpaths = ["tests"]
addopts = "-v --tb=short" addopts = "-v --tb=short"

View File

@ -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()

View File

@ -37,10 +37,10 @@ def require_credentials(kwork_credentials):
return kwork_credentials return kwork_credentials
@pytest.fixture(scope="session") @pytest.fixture(scope="module")
async def e2e_client(require_credentials): async def e2e_client(require_credentials):
""" """
E2E клиент - логинится ОДИН РАЗ для всех тестов сессии. E2E клиент - логинится ОДИН РАЗ для всех тестов в модуле.
Используется во всех тестах кроме test_auth.py (там тестируем сам логин). Используется во всех тестах кроме test_auth.py (там тестируем сам логин).
""" """
@ -52,12 +52,12 @@ async def e2e_client(require_credentials):
await client.close() await client.close()
@pytest.fixture(scope="session") @pytest.fixture(scope="module")
async def catalog_kwork_id(e2e_client): async def catalog_kwork_id(e2e_client):
""" """
Получить ID первого кворка из каталога. Получить ID первого кворка из каталога.
Выполняется ОДИН РАЗ в начале сессии и переиспользуется. Выполняется ОДИН РАЗ в начале модуля и переиспользуется.
""" """
catalog = await e2e_client.catalog.get_list(page=1) catalog = await e2e_client.catalog.get_list(page=1)
if len(catalog.kworks) > 0: if len(catalog.kworks) > 0: