-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
87 lines (70 loc) · 2.19 KB
/
run_tests.py
File metadata and controls
87 lines (70 loc) · 2.19 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
#!/usr/bin/env python3
"""
Test runner for MathModel project.
This script provides a convenient way to run tests with different options.
"""
import argparse
import logging
import os
import subprocess
import sys
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)
def main() -> int:
"""Run the tests with the specified options."""
parser = argparse.ArgumentParser(description="Run tests for MathModel project")
parser.add_argument(
"--coverage", "-c", action="store_true", help="Run tests with coverage report"
)
parser.add_argument(
"--verbose", "-v", action="store_true", help="Run tests with verbose output"
)
parser.add_argument("--test", "-t", help="Run specific test file or test function")
parser.add_argument(
"--xml",
"-x",
action="store_true",
help="Generate XML report for CI integration",
)
parser.add_argument(
"--html",
"-m",
action="store_true",
help="Generate HTML report",
)
parser.add_argument(
"--output-dir",
"-o",
default="test-results",
help="Output directory for reports",
)
args = parser.parse_args()
# Create output directory if it doesn't exist
if args.html or args.xml:
os.makedirs(args.output_dir, exist_ok=True)
logger.info(f"Created output directory: {args.output_dir}")
# Base command
cmd = ["poetry", "run", "pytest"]
# Add options
if args.verbose:
cmd.append("-v")
if args.coverage:
cmd.extend(["--cov=mathmodel", "--cov-report=term-missing"])
if args.html:
cmd.append(f"--cov-report=html:{args.output_dir}/coverage")
if args.xml:
cmd.append(f"--junitxml={args.output_dir}/test-results.xml")
if args.html:
cmd.append(f"--html={args.output_dir}/report.html")
cmd.append("--self-contained-html")
if args.test:
cmd.append(args.test)
# Run tests
logger.info(f"Running command: {' '.join(cmd)}")
result = subprocess.run(cmd)
return result.returncode
if __name__ == "__main__":
sys.exit(main())