diff --git a/tests/conftest.py b/tests/conftest.py index cd2ef68..4a24f17 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from src.database.connection import session_maker from dotenv import load_dotenv +from src.dependencies.redis import startup, shutdown load_dotenv() @@ -14,6 +15,14 @@ async def app(): return get_application() +@pytest_asyncio.fixture +async def app_with_redis(): + app = get_application() + await startup() # manually start Redis + yield app + await shutdown() # manually shutdown Redis + + @pytest_asyncio.fixture async def client(app): transport = ASGITransport(app=app) diff --git a/tests/test_redis.py b/tests/test_redis.py index 1b9cfc0..68fda3b 100644 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -1,22 +1,13 @@ import pytest from httpx import AsyncClient, ASGITransport -from api.app import get_application - @pytest.mark.asyncio -async def test_redis_ping(): - app = get_application() - - transport = ASGITransport(app=app) +async def test_redis_ping(app_with_redis): + transport = ASGITransport(app=app_with_redis) async with AsyncClient(transport=transport, base_url="http://test") as client: - # manually trigger Redis startup - await app.router.startup() - res = await client.get("/api/v1/redis/ping") assert res.status_code == 200 data = res.json() assert data["status"] == "OK" assert data["ping"] == "pong" - # manually trigger Redis shutdown - await app.router.shutdown()