"""Shared pytest configuration. The repo-root ``clipwright/`` package is made importable by ``[tool.pytest.ini_options] pythonpath = ["."]`` in the root ``pyproject.toml``, so no manual ``sys.path`` manipulation is needed here. The unit test environment deliberately omits the heavy ML stack (torch/ultralytics/mediapipe/faster-whisper) so CI stays fast. ``clipwright.pipeline.main`` imports ``ultralytics`` and ``mediapipe`` at module level, which made every test that does ``pytest.importorskip("...main")`` skip. To keep that coverage without pulling gigabytes into CI, we install minimal stand-ins *only when the real packages are absent* (the production image and a developer machine with the real deps installed are unaffected). """ from __future__ import annotations import os import sys import types from types import SimpleNamespace import pytest import _channel_seed class _FakeYOLO: def __init__(self, *args, **kwargs): self.args = args def __call__(self, *args, **kwargs): return [] def predict(self, *args, **kwargs): return [] def track(self, *args, **kwargs): return [] class _FakeDetection: def __init__(self, *args, **kwargs): pass def process(self, *args, **kwargs): return SimpleNamespace(detections=None) def close(self): pass def _is_importable(name: str) -> bool: try: __import__(name) return True except Exception: return False def _install_heavy_stubs() -> None: if not _is_importable("ultralytics"): ultralytics = types.ModuleType("ultralytics") ultralytics.YOLO = _FakeYOLO sys.modules["ultralytics"] = ultralytics if not _is_importable("mediapipe"): mediapipe = types.ModuleType("mediapipe") solutions = types.ModuleType("mediapipe.solutions") def _solution(name: str) -> types.ModuleType: mod = types.ModuleType(f"mediapipe.solutions.{name}") mod.FaceDetection = _FakeDetection mod.Detection = _FakeDetection sys.modules[f"mediapipe.solutions.{name}"] = mod return mod for name in ( "face_detection", "face_mesh", "pose", "hands", "holistic", "selfie_segmentation", ): setattr(solutions, name, _solution(name)) mediapipe.solutions = solutions sys.modules["mediapipe"] = mediapipe sys.modules["mediapipe.solutions"] = solutions _install_heavy_stubs() @pytest.fixture(scope="session", autouse=True) def _channel_profile_db(tmp_path_factory): """Point channel-profile storage at a temp SQLite DB seeded with cseea/pedro. Autouse and session-scoped so every test (including ``tests/e2e/**``, which inherits this conftest) reads the same DB-backed profiles instead of the legacy ``channels/*.json`` files. The ``CLIPWRIGHT_DB`` override is removed on teardown so nothing leaks into a later run. """ from clipwright.pipeline import profiles db_dir = tmp_path_factory.mktemp("channel-db") os.environ["CLIPWRIGHT_DB"] = str(db_dir / "clipwright.db") try: # First ``save_profile`` also runs the one-time file migration, but we # seed explicitly so the DB never depends on the checkout's files. for slug, data in _channel_seed.SEED.items(): profiles.save_profile(slug, data) yield finally: os.environ.pop("CLIPWRIGHT_DB", None)