- tests/conftest.py installs minimal ultralytics/mediapipe stand-ins only when the real packages are absent, so clipwright.pipeline.main imports in the thin unit env instead of pytest.importorskip skipping 15 modules (63 tests). Unit suite is now 779 passed / 0 skipped. - requirements-test.txt pins uvicorn==0.46.0 (the real-backend server). - dashboard: vite preview proxies /api,/videos,/thumbnails to a locally-launched backend; Playwright gains a gated (CW_E2E_REAL) real project + uvicorn webServer running the pipeline stub_env; real-backend.spec.js drives the real upload->process->clip flow. CI dashboard job installs the backend test deps. - Verified: real lane 20 passed twice in the CI container; mock-only 19 passed without the flag; backend unit/API/pipeline 779/209/127.
89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
"""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()
|