Ai
1 Star 1 Fork 2

dingyiaaa/ApiTestFramework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
DD 提交于 2025-08-26 16:11 +08:00 . 完善框架:1.增加施工通用用例
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} 次并发执行完成")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dingyiaaa/ApiTestFramework.git
git@gitee.com:dingyiaaa/ApiTestFramework.git
dingyiaaa
ApiTestFramework
ApiTestFramework
master

搜索帮助