import subprocess import sys from pathlib import Path ROOT = Path(__file__).parent.parent TESTS_DIR = Path(__file__).parent CHARTS_DIR = TESTS_DIR / "charts" REPORT_HTML = CHARTS_DIR / "report.html" DB_PATH = TESTS_DIR / "test_cases.db" def check_db(): if not DB_PATH.exists(): sys.exit(1) def run_pytest() -> int: CHARTS_DIR.mkdir(parents=True, exist_ok=True) args = [ sys.executable, "-m", "pytest", str(TESTS_DIR / "tests" / "test_schemas.py"), str(TESTS_DIR / "tests" / "test_fetch.py"), str(TESTS_DIR / "tests" / "test_tools.py"), str(TESTS_DIR / "tests" / "test_sys_prompt.py"), str(TESTS_DIR / "tests" / "test_api.py"), str(TESTS_DIR / "tests" / "test_llm_compare.py"), str(TESTS_DIR / "tests" / "test_project.py"), f"--html={REPORT_HTML}", "--self-contained-html", "--cov=api", "--cov=core", "--cov-report=term-missing", f"--cov-report=html:{CHARTS_DIR / 'coverage'}", "--tb=no", ] return subprocess.run(args, cwd=str(ROOT), check=False).returncode def open_in_browser(path: Path): if path.exists(): subprocess.Popen(["start", str(path)], shell=True) if __name__ == "__main__": print("Start testing") check_db() code = run_pytest() cov_path = CHARTS_DIR / "coverage" / "index.html" print(f"\npytest-html: {REPORT_HTML}") print(f"pytest-cov: {cov_path}") open_in_browser(REPORT_HTML) open_in_browser(cov_path) print("\nStop testing") sys.exit(code)