import json import pytest from sqlalchemy import insert from httpx import AsyncClient from app.config import settings from app.database import Base, async_session_maker, engine from app.models import URLs from app.main import app as fastapi_app from app.r import get_redis_client @pytest.fixture(autouse=True, scope="module") async def prepare_database(): assert settings.MODE == "TEST" async with engine.begin() as conn: await conn.run_sync(Base.metadata.drop_all) await conn.run_sync(Base.metadata.create_all) @pytest.fixture(autouse=True, scope="module") async def prepare_redis(): assert settings.MODE == "TEST" r = get_redis_client() r.flushdb() @pytest.fixture(scope="function") async def ac(): async with AsyncClient(app=fastapi_app, base_url="http://test") as ac: yield ac