run_all_tests.py
2.3 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
运行所有API测试脚本
Python 3.7.8 兼容
"""
import os
import sys
import subprocess
from typing import List, Tuple
def run_script(script_path: str, args: List[str] = None) -> Tuple[bool, str]:
"""运行单个测试脚本"""
cmd = [sys.executable, script_path]
if args:
cmd.extend(args)
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=os.path.dirname(__file__)
)
return result.returncode == 0, result.stdout + result.stderr
except Exception as e:
return False, str(e)
def main():
"""主函数:按顺序运行所有测试"""
print("=" * 60)
print("Apple ERP API 测试套件")
print("=" * 60)
# 测试脚本列表(按执行顺序)
tests = [
("认证登录测试", "test_auth.py", ["admin", "password"]),
("用户管理测试", "test_users.py", []),
("角色管理测试", "test_roles.py", []),
("菜单管理测试", "test_menus.py", []),
("字典管理测试", "test_dicts.py", []),
]
success_count = 0
total_count = len(tests)
for test_name, script_name, args in tests:
print(f"\n{'='*20} {test_name} {'='*20}")
script_path = os.path.join(os.path.dirname(__file__), script_name)
if not os.path.exists(script_path):
print(f"❌ 脚本不存在: {script_path}")
continue
success, output = run_script(script_path, args)
if success:
print(f"✅ {test_name} 执行成功")
success_count += 1
else:
print(f"❌ {test_name} 执行失败")
# 显示输出(截取前500字符避免过长)
if output:
print("输出:")
print(output[:500] + ("..." if len(output) > 500 else ""))
# 总结
print("\n" + "=" * 60)
print(f"测试完成: {success_count}/{total_count} 个测试通过")
print("=" * 60)
if success_count == total_count:
print("🎉 所有测试都通过了!")
return 0
else:
print("⚠️ 部分测试失败,请检查输出信息")
return 1
if __name__ == "__main__":
sys.exit(main())