You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pytest-html是否支持合并两次不同pytest运行生成的测试报告?

pytest两份html报告合并方案

方案1:从执行流程优化,避免后续合并(最推荐)

你可以直接调整用例标记和执行逻辑,一次运行直接生成单份报告,不需要做合并操作:

  • 给所有串行用例添加两个标记:@pytest.mark.serial、@pytest.mark.xdist_group(name="serial"),加了xdist_group标记的用例都会被分配到同一个执行节点按顺序运行,满足串行执行要求
  • 直接执行一次pytest命令即可同时跑并行、串行用例,生成单份报告:
pytest -n auto --dist=loadfile --html=final_report.html

方案2:合并已生成的两份报告

如果已经固定执行逻辑会生成report1.html、report2.html两份报告,可以用pytest-merge工具完成合并:

  • 先安装依赖包:
pip install pytest-merge
  • 执行合并命令:
pytest-merge report1.html report2.html --output merged_report.html

方案3:通过JUnit XML中转合并

如果方案2出现样式兼容问题,可以用XML中转的方式合并:

  • 调整原执行命令,每次运行同时输出JUnit XML格式结果:
# 运行并行用例
pytest -n auto -m "not serial" --dist=loadfile --html=report1.html --junitxml=result1.xml
# 运行串行用例
pytest -n auto -m "serial" --dist=loadfile --html=report2.html --junitxml=result2.xml
  • 用Python脚本合并两份XML的测试用例节点,生成merged_result.xml,再通过junit2html工具生成最终报告:
junit2html merged_result.xml final_report.html

内容的提问来源于stack exchange,提问作者user17034571

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 16:06:03