-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·188 lines (155 loc) · 5.53 KB
/
run_tests.py
File metadata and controls
executable file
·188 lines (155 loc) · 5.53 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
"""
Script to run the test suite for MCP Multi-Server Client.
Usage:
python run_tests.py [options]
Options:
-v, --verbose : Increase verbosity of output
-x, --exit-first : Exit after first test failure
--npx-only : Run only npx server tests
--python-only : Run only Python server tests
--cleanup-only : Run only server cleanup and error handling tests
--filesystem-only : Run only filesystem server tests
--transport-only : Run only transport tests (STDIO, SSE, HTTP)
--all : Run all tests including slow or unreliable ones
--skip-slow : Skip slow tests that might be unreliable in CI
--cli-only : Run only CLI and shell script tests
--shell-only : Run only shell script tests
"""
import sys
import pytest
def main():
"""Run the test suite."""
args = sys.argv[1:]
shell_test_flag = False
# Define test categories
core_tests = [
"tests/test_servers.py",
"tests/test_transports.py",
]
npx_tests = [
"tests/test_npx_servers.py",
"tests/test_playwright_port_handling.py"
]
additional_tests = [
"tests/test_fetch_server.py",
"tests/test_additional_servers.py",
"tests/test_uvx_transport.py",
]
filesystem_tests = [
"tests/test_filesystem_server.py",
]
transport_tests = [
"tests/test_echo_transports.py",
"tests/test_transports.py",
"tests/test_all_transports.py",
]
cleanup_tests = [
"tests/test_server_cleanup.py",
"tests/test_error_handling.py"
]
cli_tests = [
"test_client_behavior.py",
"test_fixed_client.py",
]
shell_tests = [
"./test-readme-examples.sh",
"./test-cli-examples.sh",
"./test-server-specific.sh",
]
# Default to core and cleanup tests
pytest_args = []
pytest_args.extend(core_tests)
pytest_args.extend(cleanup_tests)
# Handle verbose flag
if "-v" in args or "--verbose" in args:
pytest_args.append("-v")
if "-v" in args:
args.remove("-v")
if "--verbose" in args:
args.remove("--verbose")
# Handle exit first flag
if "-x" in args or "--exit-first" in args:
pytest_args.append("-x")
if "-x" in args:
args.remove("-x")
if "--exit-first" in args:
args.remove("--exit-first")
# Handle server type filtering
if "--npx-only" in args:
# Use the dedicated NPX tests files
pytest_args = npx_tests
args.remove("--npx-only")
if "--python-only" in args:
# Only include test_servers.py and filter for Python
pytest_args = ["tests/test_servers.py"]
pytest_args.append("-k")
pytest_args.append("python")
args.remove("--python-only")
if "--cleanup-only" in args:
# Only run cleanup and error handling tests
pytest_args = cleanup_tests
args.remove("--cleanup-only")
if "--filesystem-only" in args:
# Only run filesystem server tests
pytest_args = filesystem_tests
args.remove("--filesystem-only")
if "--transport-only" in args:
# Only run transport tests
pytest_args = transport_tests
args.remove("--transport-only")
if "--cli-only" in args:
# Only run CLI-related tests
pytest_args = cli_tests
# Add shell script tests after running pytest
args.remove("--cli-only")
# Run shell tests after pytest
shell_test_flag = True
if "--shell-only" in args:
# Only run shell script tests
pytest_args = [] # Clear pytest args
shell_test_flag = True
args.remove("--shell-only")
if "--all" in args:
# Run all tests
pytest_args = core_tests + npx_tests + additional_tests + filesystem_tests + transport_tests + cleanup_tests + cli_tests
# Add shell script tests after running pytest
shell_test_flag = True
args.remove("--all")
if "--skip-slow" in args:
# Skip potentially slow or unreliable tests in CI
pytest_args.append("-k")
pytest_args.append("not test_playwright")
args.remove("--skip-slow")
# Add any remaining arguments
pytest_args.extend(args)
# Run pytest tests if args exist
exit_code = 0
if pytest_args:
print(f"Running pytest tests with arguments: {pytest_args}")
exit_code = pytest.main(pytest_args)
# Run shell tests if needed
if shell_test_flag:
import subprocess
import os
# Make sure all shell scripts are executable
for script in shell_tests:
if os.path.exists(script):
os.chmod(script, 0o755)
print("\n=== Running shell script tests ===")
for script in shell_tests:
if os.path.exists(script):
print(f"\nRunning {script}...")
try:
result = subprocess.run(script, shell=True, check=False)
if result.returncode != 0:
print(f"Shell test {script} failed with exit code {result.returncode}")
exit_code = result.returncode
except Exception as e:
print(f"Error running {script}: {e}")
exit_code = 1
else:
print(f"Script {script} not found, skipping")
sys.exit(exit_code)
if __name__ == "__main__":
main()