from collections.abc import AsyncGenerator import pytest from fastapi.testclient import TestClient from pydantic_settings import SettingsConfigDict from redis import asyncio as aioredis from pssecret.main import app from pssecret.settings import Settings, get_settings class TestSettings(Settings): model_config = SettingsConfigDict(env_file=".test.env") @pytest.fixture def settings() -> Settings: return TestSettings() @pytest.fixture() async def redis_server(settings: Settings) -> AsyncGenerator[aioredis.Redis]: redis = await aioredis.from_url(str(settings.redis_url)) yield redis await redis.flushdb() def get_test_settings() -> Settings: return TestSettings() @pytest.fixture(scope="session") def client() -> TestClient: client_ = TestClient(app) app.dependency_overrides[get_settings] = get_test_settings return client_