import importlib.util import sys from pathlib import Path import pytest REPO_ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(REPO_ROOT)) def _load_pipeline(name: str): """Import a pipeline's publish.py under a unique module name. The three pipelines each define a module called `publish`, so they cannot be imported by plain name without colliding in sys.modules. """ spec = importlib.util.spec_from_file_location( f"{name}_publish", REPO_ROOT / "pipelines" / name / "publish.py" ) module = importlib.util.module_from_spec(spec) sys.modules[spec.name] = module spec.loader.exec_module(module) return module @pytest.fixture(scope="session") def songs(): return _load_pipeline("songs") @pytest.fixture def repo(tmp_path): """Build a source tree of .md files: write(relative_path, frontmatter, body).""" def write(rel: str, front: str = "", body: str = "") -> Path: path = tmp_path / rel path.parent.mkdir(parents=True, exist_ok=True) path.write_text(f"---\n{front}\n---\n\n{body}\n", encoding="utf-8") return path write.root = tmp_path return write