-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathrun_test.py
More file actions
executable file
·96 lines (79 loc) · 2.91 KB
/
run_test.py
File metadata and controls
executable file
·96 lines (79 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from pathlib import Path
import subprocess
import pstats
def run_pytest(args):
"""
Run pytest in a fresh Python subprocess.
Returns the pytest exit code.
"""
cmd = [sys.executable, "-m", "pytest", *args]
print("\n>>>", " ".join(cmd), "\n")
return subprocess.run(cmd, check=False).returncode
def main() -> int:
# ------------------------------------------------------------------
# Anchor execution to project root
# ------------------------------------------------------------------
ROOT = Path(__file__).resolve().parent
os.chdir(ROOT)
# ------------------------------------------------------------------
# Clean previous coverage artifacts
# ------------------------------------------------------------------
Path("coverage.xml").unlink(missing_ok=True)
Path(".coverage").unlink(missing_ok=True)
prof_path = ROOT / Path("prof/combined.prof")
prof_path.parent.mkdir(parents=True, exist_ok=True)
prof_path.write_bytes(b"")
# ------------------------------------------------------------------
# 1) Doctests (source code)
# ------------------------------------------------------------------
doctest_args = [
"src/pydna",
"--doctest-modules",
"--cov=pydna",
"--cov-report=html",
"--cov-report=xml",
"--cov-append",
"--durations=10",
"-vvv",
]
rc_doctests = run_pytest(doctest_args)
# ------------------------------------------------------------------
# 2) Unit tests (test suite)
# ------------------------------------------------------------------
unit_test_args = [
"tests",
"--cov=pydna",
"--cov-report=html",
"--cov-report=xml",
"--cov-append",
"--durations=10",
"-vvv",
"--profile",
]
rc_unit_tests = run_pytest(unit_test_args)
# ------------------------------------------------------------------
# Optional: profile summary
# ------------------------------------------------------------------
if prof_path.exists() and prof_path.stat().st_size > 0:
print("\n=== Profiling summary (top cumulative) ===\n")
stats = pstats.Stats(str(prof_path))
SRC = (Path(ROOT) / "src" / "pydna").resolve()
stats.stats = {
k: v
for k, v in stats.stats.items()
if Path(k[0]).resolve().is_relative_to(SRC)
}
stats.sort_stats("tottime")
stats.print_stats()
# ------------------------------------------------------------------
# Final report
# ------------------------------------------------------------------
print(f"\nrun_test.py return code for doctests : {rc_doctests}")
print(f"run_test.py return code for unit tests: {rc_unit_tests}")
return rc_doctests + rc_unit_tests
if __name__ == "__main__":
sys.exit(main())