45 lines
898 B
Python
45 lines
898 B
Python
"""
|
|
测试运行脚本
|
|
运行所有测试
|
|
"""
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def run_tests():
|
|
"""运行所有测试"""
|
|
project_root = Path(__file__).parent.absolute()
|
|
|
|
# 构建 pytest 命令
|
|
cmd = [
|
|
sys.executable,
|
|
'-m',
|
|
'pytest',
|
|
str(project_root / 'test'),
|
|
'-v',
|
|
'--tb=short',
|
|
'-ra'
|
|
]
|
|
|
|
print("=" * 60)
|
|
print("开始运行测试...")
|
|
print("=" * 60)
|
|
print(f"测试目录:{project_root / 'test'}")
|
|
print("=" * 60)
|
|
|
|
# 运行测试
|
|
result = subprocess.run(cmd, cwd=project_root)
|
|
|
|
print("=" * 60)
|
|
if result.returncode == 0:
|
|
print("所有测试通过!")
|
|
else:
|
|
print(f"测试失败,退出码:{result.returncode}")
|
|
print("=" * 60)
|
|
|
|
return result.returncode
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(run_tests())
|