-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
89 lines (76 loc) · 1.99 KB
/
run_tests.py
File metadata and controls
89 lines (76 loc) · 1.99 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
#!/usr/bin/env python3
"""
Test runner script with coverage support.
"""
import subprocess
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
def run_tests(coverage=True):
"""Run tests with optional coverage."""
# Change to project root
project_root = Path(__file__).parent
os.chdir(project_root)
# Ensure .coveragerc exists
if not Path('.coveragerc').exists():
print("Creating .coveragerc...")
create_coveragerc()
# Base pytest command
cmd = [sys.executable, '-m', 'pytest', 'tests']
if coverage:
# Add coverage options
cmd.extend([
'--cov=.',
'--cov-config=.coveragerc',
'--cov-report=html:htmlcov',
'--cov-report=term-missing',
'--cov-report=xml',
'--cov-fail-under=70'
])
# Add other options
cmd.extend([
'--timeout=300',
'-v',
'--tb=short'
])
# Add any additional arguments
if len(sys.argv) > 1:
if '--coverage' not in sys.argv:
cmd.extend(sys.argv[1:])
print(f"Running: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, check=False)
return result.returncode
except Exception as e:
print(f"Error running tests: {e}")
return 1
def create_coveragerc():
"""Create default .coveragerc file."""
content = """[run]
branch = True
source = .
omit =
*/tests/*
test_*.py
*/test_*.py
*/__pycache__/*
*/venv/*
*/env/*
*/.venv/*
setup.py
run_tests.py
conftest.py
[report]
exclude_lines =
pragma: no cover
def __repr__
raise NotImplementedError
if __name__ == .__main__.:
"""
with open('.coveragerc', 'w') as f:
f.write(content)
if __name__ == '__main__':
# Check if --coverage flag is present
use_coverage = '--coverage' in sys.argv or len(sys.argv) == 1
sys.exit(run_tests(coverage=use_coverage))