Pytest测试报告生成专题

pytest 中,你可以使用多个选项生成不同格式的测试报告。以下是几种常用的生成测试报告的方法:

1. 生成简单的测试结果文件

你可以使用 pytest--junitxml 选项生成一个 XML 格式的测试报告,这个报告可以与 CI/CD 工具集成。

bash 复制代码
pytest --junitxml=report.xml

这将在当前目录下生成一个名为 report.xml 的文件,其中包含测试结果的详细信息。

2. 生成 HTML 格式的测试报告

要生成更易于阅读的 HTML 格式的报告,可以使用 pytest-html 插件。

安装 pytest-html 插件
bash 复制代码
pip install pytest-html
生成 HTML 报告

安装完成后,你可以通过以下命令生成 HTML 格式的测试报告:

bash 复制代码
pytest --html=report.html

这个命令会在当前目录下生成一个名为 report.html 的文件,你可以在浏览器中打开并查看详细的测试结果。

3. 生成 Allure 报告

Allure 报告是一种高度可定制化的报告格式,可以提供详细的测试执行信息。

安装 allure-pytest 插件
bash 复制代码
pip install allure-pytest
生成 Allure 报告

运行以下命令生成 Allure 报告的原始数据:

bash 复制代码
pytest --alluredir=allure-results

然后你需要使用 Allure 命令行工具来生成 HTML 格式的报告:

bash 复制代码
allure generate allure-results -o allure-report --clean

你可以通过以下命令在浏览器中打开报告:

bash 复制代码
allure open allure-report

4. 生成 Markdown 报告

如果你更喜欢 Markdown 格式的报告,可以使用 pytest-md 插件。

安装 pytest-md 插件
bash 复制代码
pip install pytest-md
生成 Markdown 报告

运行以下命令生成 Markdown 格式的测试报告:

bash 复制代码
pytest --md=report.md

这将在当前目录下生成一个名为 report.md 的文件。

5. 其他格式和工具

如果你有其他特定格式的需求,可能需要寻找或者编写特定的 pytest 插件。pytest 提供了丰富的插件生态,可以满足大多数的测试报告需求。

相关推荐
丿罗小黑4 小时前
Pytest项目_day04(Python做接口请求)
pytest
丿罗小黑14 小时前
Pytest项目_day09(skip、skipif跳过)
pytest
₯㎕星空&繁华1 天前
接口自动化-pytest
运维·经验分享·笔记·自动化·pytest·接口
丿罗小黑3 天前
Pytest项目_day06(requests中Session的用法)
pytest
测试开发技术3 天前
软件测试中,pytest 如何运行多个文件或整个目录?
自动化测试·pytest·接口测试·面试题
鱼骨不是鱼翅6 天前
自动化框架pytest
运维·自动化·pytest
2025年一定要上岸9 天前
【pytest高阶】-2- 内置hook插件扩展机制和定制开发
pytest
2025年一定要上岸11 天前
【pytest高阶】源码的走读方法及插件hook
运维·前端·python·pytest
惜.己13 天前
pytest中使用ordering控制函数的执行顺序
开发语言·python·pytest
惜.己14 天前
pytest中使用skip跳过某个函数
开发语言·python·测试工具·pytest