import os import tempfile from collections.abc import AsyncIterator from pathlib import Path import pytest # Environnement de test AVANT tout import de l'app _tmp = Path(tempfile.mkdtemp(prefix="ohm-test-")) os.environ["OHM_DATA_DIR"] = str(_tmp) os.environ["OHM_DOWNLOAD_DIR"] = str(_tmp / "downloads") os.environ["OHM_DATABASE_PATH"] = str(_tmp / "test.db") os.environ["OHM_SECRET_KEY"] = "test-secret-key-with-32-bytes-minimum!" from app.config import get_settings from app.db import db @pytest.fixture(scope="session") def anyio_backend() -> str: return "asyncio" @pytest.fixture(autouse=True) async def database() -> AsyncIterator[None]: """DB fraƮche par test.""" get_settings.cache_clear() await db.connect() for table in ( "users", "refresh_tokens", "downloads", "metadata_cache", "settings", "favorites", "watch_progress", ): await db.execute(f"DELETE FROM {table}") yield await db.close()