fix: use sync wrapper for async fixtures (avoid pytest-asyncio issues)
This commit is contained in:
parent
61d5cefe80
commit
6b86767606
@ -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"
|
||||||
|
|
||||||
|
|||||||
@ -38,32 +38,42 @@ 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
|
||||||
|
|
||||||
|
async def create():
|
||||||
|
return await KworkClient.login(
|
||||||
username=require_credentials["username"],
|
username=require_credentials["username"],
|
||||||
password=require_credentials["password"],
|
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 первого кворка из каталога.
|
||||||
|
|
||||||
Выполняется ОДИН РАЗ в начале модуля и переиспользуется.
|
Выполняется ОДИН РАЗ в начале модуля и переиспользуется.
|
||||||
"""
|
"""
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
async def get():
|
||||||
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:
|
||||||
return catalog.kworks[0].id
|
return catalog.kworks[0].id
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
return asyncio.new_event_loop().run_until_complete(get())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def slowmo(request):
|
def slowmo(request):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user