from __future__ import annotations import os import sys from collections.abc import Generator from pathlib import Path import pytest from fastapi.testclient import TestClient # Ensure project root is on PYTHONPATH for `import app` ROOT_DIR = Path(__file__).resolve().parents[1] if str(ROOT_DIR) not in sys.path: sys.path.insert(0, str(ROOT_DIR)) os.environ.setdefault("DISABLE_STARTUP_EVENTS", "true") from app import main # noqa: E402 from app.database.models import ProductDatabase # noqa: E402 @pytest.fixture def client(tmp_path) -> Generator[TestClient, None, None]: db_path = tmp_path / "products.db" main.product_database = ProductDatabase(str(db_path)) main.product_catalog = [] main.product_id_to_index = {} main.reindexing = False with TestClient(main.app) as test_client: yield test_client