"""Общие фикстуры: тестовый конфиг, приложение с фейковым эмбеддером, клиент.""" from __future__ import annotations import sys from pathlib import Path import pytest from fastapi.testclient import TestClient sys.path.insert(0, str(Path(__file__).resolve().parent)) # импорт fakes/synth из tests/ from fakes import FakeEmbedder # noqa: E402 from app.config import Config # noqa: E402 from app.main import create_app # noqa: E402 def make_config(**overrides) -> Config: """Конфиг с боевыми правилами, но мелкими лимитами для тестов 413.""" defaults = dict( api_key=None, host="127.0.0.1", port=8000, workers=1, model_name="fake-model", device="cpu", image_size=224, torch_home=None, max_image_bytes=1024 * 1024, # 1 МБ на файл min_image_dim=32, max_references=4, threshold_match=0.55, threshold_no_match=0.40, log_level="WARNING", ) defaults.update(overrides) return Config(**defaults) @pytest.fixture def config() -> Config: return make_config() @pytest.fixture def app(config: Config): application = create_app(config, embedder=FakeEmbedder()) with TestClient(application, raise_server_exceptions=False) as client: yield application @pytest.fixture def client(app): # Lifespan (загрузка фейка) уже отработал внутри фикстуры app return TestClient(app, raise_server_exceptions=False)