Files
douyin_guaji-main/run_tests.py
T
Your Name f92933641f feat: Enhance documentation and clean up code structure
- Added comprehensive documentation for the unified screenshot and score recording process in the new markdown file.
- Improved existing markdown files by adding spacing for better readability.
- Cleaned up code by removing unnecessary blank lines across various scripts, enhancing overall code clarity.
- Updated configuration settings to reflect recent changes and ensure consistency across the project.
- Enhanced logging mechanisms to support better debugging and monitoring.
2025-12-25 16:11:25 +08:00

149 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
测试运行脚本
===========
用法:
python run_tests.py # 运行所有测试
python run_tests.py --unit # 只运行单元测试
python run_tests.py --integration # 只运行集成测试
python run_tests.py --coverage # 生成覆盖率报告
python run_tests.py --parallel # 并行运行测试
"""
import sys
import subprocess
import argparse
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description="运行测试套件")
parser.add_argument(
"--unit",
action="store_true",
help="只运行单元测试"
)
parser.add_argument(
"--integration",
action="store_true",
help="只运行集成测试"
)
parser.add_argument(
"--coverage",
action="store_true",
help="生成覆盖率报告"
)
parser.add_argument(
"--parallel",
action="store_true",
help="并行运行测试(使用pytest-xdist)"
)
parser.add_argument(
"--verbose",
"-v",
action="store_true",
help="详细输出"
)
parser.add_argument(
"--markers",
"-m",
help="只运行指定标记的测试(例如: -m unit)"
)
parser.add_argument(
"--file",
"-f",
help="只运行指定文件的测试"
)
args = parser.parse_args()
# 构建pytest命令
cmd = ["python", "-m", "pytest"]
if args.unit:
cmd.extend(["tests/unit"])
elif args.integration:
cmd.extend(["tests/integration"])
elif args.file:
cmd.append(args.file)
else:
cmd.append("tests")
if args.markers:
cmd.extend(["-m", args.markers])
if args.parallel:
import multiprocessing
num_workers = multiprocessing.cpu_count()
cmd.extend(["-n", str(num_workers)])
if args.verbose:
cmd.append("-vv")
if args.coverage:
cmd.extend([
"--cov=.",
"--cov-report=html:htmlcov",
"--cov-report=term-missing"
])
# 运行测试
print(f"运行命令: {' '.join(cmd)}")
result = subprocess.run(cmd)
if result.returncode == 0:
print("\n✅ 所有测试通过!")
if args.coverage:
print("\n📊 覆盖率报告已生成: htmlcov/index.html")
else:
print("\n❌ 测试失败")
sys.exit(1)
if __name__ == "__main__":
main()