-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·105 lines (83 loc) · 2.68 KB
/
run_tests.py
File metadata and controls
executable file
·105 lines (83 loc) · 2.68 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
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
"""
Test runner script for CI/CD pipelines and local development
"""
import argparse
import subprocess
import sys
from pathlib import Path
def run_command(cmd, description="Running command"):
"""Run a command and return the result"""
print(f"\n{description}...")
print(f"Command: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.stdout:
print("STDOUT:")
print(result.stdout)
if result.stderr:
print("STDERR:")
print(result.stderr)
return result
def main():
parser = argparse.ArgumentParser(description="Run tests for weather MCP server")
parser.add_argument(
"--type",
choices=["unit", "integration", "all"],
default="all",
help="Type of tests to run (default: all)",
)
parser.add_argument(
"--coverage", action="store_true", help="Run tests with coverage reporting"
)
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser.add_argument(
"--fail-fast", "-x", action="store_true", help="Stop on first failure"
)
parser.add_argument(
"--parallel", "-n", type=int, help="Number of parallel workers for pytest-xdist"
)
args = parser.parse_args()
# Check if we're in the right directory
if not Path("weather_mcp").exists():
print("Error: Must run from project root directory")
sys.exit(1)
# Build pytest command
cmd = ["python", "-m", "pytest"]
# Add test type marker
if args.type == "unit":
cmd.extend(["-m", "unit"])
elif args.type == "integration":
cmd.extend(["-m", "integration"])
# "all" runs everything (no marker filter)
# Add coverage if requested
if args.coverage:
cmd.extend(
[
"--cov=weather_mcp",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
]
)
# Add verbosity
if args.verbose:
cmd.append("-v")
# Add fail-fast
if args.fail_fast:
cmd.append("-x")
# Add parallel execution
if args.parallel:
cmd.extend(["-n", str(args.parallel)])
# Add test directory
cmd.append("tests/")
# Run the tests
result = run_command(cmd, f"Running {args.type} tests")
if result.returncode == 0:
print(f"\n✅ {args.type.capitalize()} tests passed!")
if args.coverage:
print("📊 Coverage report generated in htmlcov/index.html")
else:
print(f"\n❌ {args.type.capitalize()} tests failed!")
sys.exit(1)
if __name__ == "__main__":
main()