clipwright/tests/e2e/pipeline/conftest.py
pedro-bento 0040aa49da
All checks were successful
CI / dashboard-e2e (push) Successful in 1m44s
CI / unit (push) Successful in 29s
CI / backend-e2e (push) Successful in 1m17s
test/e2e-coverage (#5)
Reviewed-on: #5
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 22:28:46 +01:00

69 lines
2 KiB
Python

"""Pipeline E2E fixtures.
The tests here run the REAL CLI (``python -m clipwright.pipeline.main``) with
real ffmpeg, but the child interpreter is started with ``stub_env`` on
``PYTHONPATH``. ``stub_env/sitecustomize.py`` swaps the ML and network edges
(ultralytics/mediapipe, ASR, Gemini) for deterministic fakes, so no model is
downloaded and no request leaves the process. Mark ML-backed variants with
``pytest.mark.ml``; those run against ``requirements-ml-e2e.txt`` instead.
"""
import os
import subprocess
import sys
from pathlib import Path
import pytest
pytestmark = pytest.mark.pipeline
REPO_ROOT = Path(__file__).resolve().parents[3]
STUB_ENV = Path(__file__).resolve().parent / "stub_env"
@pytest.fixture(scope="session")
def stub_env_dir():
"""Directory holding ``sitecustomize.py`` for the pipeline child."""
assert (STUB_ENV / "sitecustomize.py").is_file()
return STUB_ENV
@pytest.fixture
def pipeline_env(stub_env_dir, tmp_path):
"""Environment for a pipeline subprocess: stub env on PYTHONPATH, no LLM."""
env = dict(os.environ)
env.pop("LLM_BASE_URL", None)
env.pop("LLM_MODEL", None)
env["GEMINI_API_KEY"] = "stub-gemini-key"
env["PYTHONPATH"] = os.pathsep.join(
[str(stub_env_dir), str(REPO_ROOT), env.get("PYTHONPATH", "")]
).strip(os.pathsep)
env["PYTHONHASHSEED"] = "0"
env["TZ"] = "UTC"
# Keep output inside the test's tmp tree unless the caller overrides it.
env.setdefault("TRANSCRIBE_BACKEND", "whisper")
return env
@pytest.fixture
def run_pipeline(pipeline_env):
"""Run the real CLI; returns the CompletedProcess.
Usage: ``run_pipeline(media.six, "-o", str(out))``.
"""
def _run(input_path, *extra, timeout=180):
cmd = [
sys.executable, "-u", "-m", "clipwright.pipeline.main",
"-i", str(input_path), *extra,
]
return subprocess.run(
cmd,
cwd=str(REPO_ROOT),
env=pipeline_env,
capture_output=True,
text=True,
timeout=timeout,
)
return _run