from pathlib import Path import pytest from fastapi.testclient import TestClient from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @pytest.fixture() def client(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): monkeypatch.setenv("DATA_DIR", str(tmp_path)) from app.config import Settings import app.config as config_module import app.db as db_module import app.main as main_module from app.services import rate_limit as rate_limit_module settings = Settings(_env_file=None, DATA_DIR=tmp_path) config_module.settings = settings # Multi-create tests are not about rate limits; the dedicated test sets 2/s. monkeypatch.setattr(config_module.settings, "rate_limit_per_second", 10_000) rate_limit_module.reset() engine = create_engine( settings.db_url, connect_args={"check_same_thread": False}, ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) db_module.engine = engine db_module.SessionLocal = SessionLocal main_module.engine = engine with TestClient(main_module.app) as test_client: yield test_client