"""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 sys import types from types import SimpleNamespace 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()