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

相关推荐
Test.X18 小时前
学习16天:pytest学习
学习·pytest
唐古乌梁海2 天前
【pytest 】 pytest 生命周期
pytest
专职3 天前
pytest详细教程
开发语言·python·pytest
乄捷径3 天前
pytest入门到熟练
pytest
专职3 天前
pytest+requests+allure生成接口自动化测试报告
开发语言·python·pytest
小熊出擊4 天前
【pytest】fixture 内省(Introspection)测试上下文
python·单元测试·pytest
小熊出擊5 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
小熊出擊6 天前
【pytest】使用 marker 向 fixture 传递数据
python·pytest
wa的一声哭了6 天前
Deep Learning Optimizer | Adam、AdamW
人工智能·深度学习·神经网络·机器学习·自然语言处理·transformer·pytest
专职8 天前
pytest生成测试用例,allure生成测试报告
测试用例·pytest