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 提供了丰富的插件生态,可以满足大多数的测试报告需求。

相关推荐
bjwuzh1 天前
使用pytest实现参数化后,控制台输出的日志是乱码
pytest
2025年一定要上岸2 天前
pytest框架 - 第二集 allure报告
pytest
头疼的程序员3 天前
allure生成测试报告(搭配Pytest、allure-pytest)
测试工具·pytest
文人sec4 天前
接口自动化测试设计思路--设计实战
python·https·单元测试·自动化·pytest
测试开发Kevin5 天前
从投入产出、效率、上手难易度等角度综合对比 pytest 和 unittest 框架
python·pytest
测试开发Kevin8 天前
以pytest_addoption 为例,讲解pytest框架中钩子函数的应用
python·pytest
川石教育13 天前
Pytest中的fixture装饰器详解
python自动化测试·pytest·pytest自动化测试框架·pytest测试框架·pytest单元测试框架
春风又。13 天前
接口自动化——参数化
python·测试工具·自动化·pytest
XTY0016 天前
mac电脑pytest生成测试报告
pytest
程序员的世界你不懂16 天前
pytest-前后置及fixture运用
pytest