代码拉取完成,页面将自动刷新
import os
import shutil
import subprocess
from concurrent.futures import ThreadPoolExecutor, as_completed
def run_pytest_with_allure(run_index=1):
# 报告路径,每次加上索引避免覆盖
result_dir = f"reports/reports_{run_index}"
report_dir = f"reports/allure-report_{run_index}"
# 清理旧报告
if os.path.exists(result_dir):
shutil.rmtree(result_dir)
if os.path.exists(report_dir):
shutil.rmtree(report_dir)
# 运行 pytest 收集 allure 数据
print(f"---开始执行接口测试用例,第 {run_index} 次...")
ret = subprocess.call([
"pytest",
"testcases/test_api.py",
"--alluredir", result_dir,
#"-n", "2" # pytest 内部并发 2 个线程/进程执行用例
])
if ret != 0:
print(f"---第 {run_index} 次执行有失败,请查看报告")
# 生成 HTML 报告
print(f"---第 {run_index} 次生成 Allure 报告...")
subprocess.call([r"D:\allure-2.13.2\bin\allure.bat", "generate", result_dir, "-o", report_dir, "--clean"])
# 可选:打开报告
subprocess.call([r"D:\allure-2.13.2\bin\allure.bat", "open", report_dir])
if __name__ == '__main__':
total_runs = 1 # 总共执行 10 次
max_workers = 1 # 同时并发 3 个 pytest 进程
with ThreadPoolExecutor(max_workers=max_workers) as executor:
# 提交任务
futures = [executor.submit(run_pytest_with_allure, i) for i in range(1, total_runs + 1)]
# 等待所有任务完成
for future in as_completed(futures):
try:
future.result()
except Exception as e:
print(f"执行过程中出现异常: {e}")
print(f"{total_runs} 次并发执行完成")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。