"""Run pytest for every service that has tests, each in its own env with its own requirements.txt.""" import subprocess import sys from pathlib import Path def has_tests(service: Path) -> bool: return any(service.rglob("test_*.py")) or any(service.rglob("*_test.py")) def main() -> int: failed: list[str] = [] services = sorted(p for p in Path("services").glob("*/") if p.is_dir()) if Path("services").is_dir() else [] for service in services: if not has_tests(service): print(f"[{service.name}] no tests — skipped") continue cmd = ["uv", "run", "--no-project", "--with", "pytest"] req = service / "requirements.txt" if req.is_file(): cmd += ["--with-requirements", str(req)] cmd += ["pytest", "-q", str(service)] print(f"[{service.name}] {' '.join(cmd)}", flush=True) if subprocess.run(cmd).returncode != 0: failed.append(service.name) if failed: print(f"tests failed: {', '.join(failed)}") return 1 return 0 if __name__ == "__main__": sys.exit(main())