fix: use sync wrapper for async fixtures (avoid pytest-asyncio issues)

This commit is contained in:
root 2026-03-30 00:05:20 +00:00
parent 61d5cefe80
commit 6b86767606
2 changed files with 21 additions and 12 deletions

View File

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

View File

@ -38,31 +38,41 @@ def require_credentials(kwork_credentials):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
async def e2e_client(require_credentials): def e2e_client(require_credentials):
""" """
E2E клиент - логинится ОДИН РАЗ для всех тестов в модуле. E2E клиент - логинится ОДИН РАЗ для всех тестов в модуле.
Используется во всех тестах кроме test_auth.py (там тестируем сам логин). Используется во всех тестах кроме test_auth.py (там тестируем сам логин).
""" """
client = await KworkClient.login( import asyncio
username=require_credentials["username"],
password=require_credentials["password"], async def create():
) return await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
client = asyncio.new_event_loop().run_until_complete(create())
yield client yield client
await client.close() asyncio.new_event_loop().run_until_complete(client.close())
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
async def catalog_kwork_id(e2e_client): def catalog_kwork_id(e2e_client):
""" """
Получить ID первого кворка из каталога. Получить ID первого кворка из каталога.
Выполняется ОДИН РАЗ в начале модуля и переиспользуется. Выполняется ОДИН РАЗ в начале модуля и переиспользуется.
""" """
catalog = await e2e_client.catalog.get_list(page=1) import asyncio
if len(catalog.kworks) > 0:
return catalog.kworks[0].id async def get():
return None catalog = await e2e_client.catalog.get_list(page=1)
if len(catalog.kworks) > 0:
return catalog.kworks[0].id
return None
return asyncio.new_event_loop().run_until_complete(get())
@pytest.fixture(scope="function") @pytest.fixture(scope="function")