- 16 个业务模块,856 个测试用例,40 个 E2E 测试 - 单一 React 19 前端 + PlatformSwitcher 二合一切换 - Flask 后端支持 scenario/dcloud_module/dcloud_e2e/dcloud_all 四种任务类型 - E2E 测试面板:API 全链路(8条) + UI 点击(3条) + 分步测试(3个) - SSE 实时日志流 + 飞书告警 + 定时调度 - 完整还原原 ToB 平台 TestPanel E2E 模块
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""运行测试并生成现代化中文测试报告 Dashboard
|
|
|
|
用法:
|
|
python scripts/run_and_report.py # 默认运行全部测试
|
|
python scripts/run_and_report.py --tests tests/data_space/ # 只跑某个模块
|
|
python scripts/run_and_report.py --no-xdist # 串行运行(调试)
|
|
python scripts/run_and_report.py --no-history # 不保存历史记录
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).parent.parent
|
|
|
|
|
|
def run(cmd: list, description: str) -> int:
|
|
print(f"\n{'━' * 60}")
|
|
print(f" {description}")
|
|
print(f"{'━' * 60}")
|
|
result = subprocess.run(cmd, cwd=str(ROOT))
|
|
return result.returncode
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="运行测试并生成 Dashboard 报告")
|
|
parser.add_argument(
|
|
"--tests",
|
|
nargs="+",
|
|
default=["tests/"],
|
|
help="测试目录或文件(默认 tests/),支持多个路径",
|
|
)
|
|
parser.add_argument(
|
|
"--no-xdist", action="store_true", help="禁用并行执行(用于调试)"
|
|
)
|
|
parser.add_argument(
|
|
"--output",
|
|
default=str(ROOT / "reports" / "report_zh.html"),
|
|
help="报告输出路径",
|
|
)
|
|
parser.add_argument(
|
|
"--no-history",
|
|
action="store_true",
|
|
help="不保存历史数据",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
# Step 1: Run tests
|
|
pytest_cmd = [sys.executable, "-m", "pytest"] + args.tests
|
|
if args.no_xdist:
|
|
pytest_cmd += [
|
|
"-p",
|
|
"no:xdist",
|
|
"--override-ini=addopts=-v --strict-markers --tb=short",
|
|
]
|
|
|
|
exit_code = run(pytest_cmd, "运行自动化测试")
|
|
|
|
# Step 2: Generate report
|
|
report_cmd = [
|
|
sys.executable,
|
|
str(ROOT / "scripts" / "generate_report.py"),
|
|
"--output",
|
|
args.output,
|
|
]
|
|
if args.no_history:
|
|
report_cmd.append("--no-history")
|
|
|
|
run(report_cmd, "生成测试报告 Dashboard")
|
|
|
|
# Step 3: Summary
|
|
print(f"\n{'━' * 60}")
|
|
if exit_code == 0:
|
|
print(" ALL TESTS PASSED")
|
|
else:
|
|
print(f" 测试完成,退出码: {exit_code}")
|
|
print(f" 报告: {args.output}")
|
|
print(f"{'━' * 60}\n")
|
|
|
|
sys.exit(exit_code)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|