-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_tests.py
More file actions
79 lines (61 loc) · 2.17 KB
/
run_tests.py
File metadata and controls
79 lines (61 loc) · 2.17 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
#!/usr/bin/env python3
"""Test runner script for Unity Docs MCP Server."""
import sys
import os
import unittest
import coverage
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def run_tests_with_coverage():
"""Run tests with coverage reporting."""
# Initialize coverage
cov = coverage.Coverage(source=['src/unity_docs_mcp'])
cov.start()
try:
# Discover and run tests
loader = unittest.TestLoader()
start_dir = os.path.join(os.path.dirname(__file__), 'tests')
suite = loader.discover(start_dir, pattern='test_*.py')
# Run tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
# Stop coverage and report
cov.stop()
cov.save()
# Print coverage report
print("\n" + "="*60)
print("COVERAGE REPORT")
print("="*60)
cov.report(show_missing=True)
# Generate HTML coverage report
try:
cov.html_report(directory='htmlcov')
print(f"\nHTML coverage report generated in 'htmlcov' directory")
except Exception as e:
print(f"Could not generate HTML report: {e}")
# Return exit code based on test results
return 0 if result.wasSuccessful() else 1
except Exception as e:
print(f"Error running tests: {e}")
return 1
finally:
cov.stop()
def run_tests_simple():
"""Run tests without coverage (fallback)."""
# Discover and run tests
loader = unittest.TestLoader()
start_dir = os.path.join(os.path.dirname(__file__), 'tests')
suite = loader.discover(start_dir, pattern='test_*.py')
# Run tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return 0 if result.wasSuccessful() else 1
if __name__ == '__main__':
try:
# Try to run with coverage first
import coverage
exit_code = run_tests_with_coverage()
except ImportError:
print("Coverage not available, running tests without coverage...")
exit_code = run_tests_simple()
sys.exit(exit_code)