"""Конфигурация и фикстуры для тестов."""
import asyncio
from collections.abc import AsyncGenerator, Generator
import pytest
from fastapi import FastAPI
from httpx import AsyncClient
from app.main import app
@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
"""Создает event loop для асинхронных тестов."""
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()
@pytest.fixture
def test_app() -> FastAPI:
"""Фикстура для тестового приложения FastAPI."""
return app
@pytest.fixture
async def async_client(test_app: FastAPI) -> AsyncGenerator[AsyncClient, None]:
"""Фикстура для асинхронного клиента."""
async with AsyncClient(app=test_app, base_url="http://test") as client:
yield client