ai-lawyer-agent/testing/run_tests.py
2026-03-23 04:51:56 +01:00

60 lines
1.3 KiB
Python

import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).parent.parent
TESTS_DIR = Path(__file__).parent
RESULTS_JSON = TESTS_DIR / "results.json"
REPORT_HTML = TESTS_DIR / "charts" / "report.html"
CHARTS_DIR = TESTS_DIR / "charts"
def run_pytest() -> int:
CHARTS_DIR.mkdir(parents=True, exist_ok=True)
args = [
sys.executable, "-m", "pytest",
str(TESTS_DIR / "tests"),
"--json-report",
f"--json-report-file={RESULTS_JSON}",
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 run_charts():
from testing.reports.charts import generate
return generate()
if __name__ == "__main__":
print("Start testing")
code = run_pytest()
charts_path = None
if RESULTS_JSON.exists():
charts_path = run_charts()
print()
print(f"pytest-html: {REPORT_HTML}")
print(f"pytest-cov: {CHARTS_DIR / 'coverage' / 'index.html'}")
print(f"charts: {charts_path or CHARTS_DIR / 'report.png'}")
print()
print("Stop testing")
sys.exit(code)