一、pytest-html 生成 html 测试报告
要求:Python 3.6+
安装:pip install pytest-html
文档:https://github.com/pytest-dev/pytest-html、https://www.cnblogs.com/linuxchao/p/linuxchao-pytest-report.html
使用方法:在命令行或 pytest.ini 配置文件 addopts 中添加选项 --html=测试报告路径
(1)命令行方式:pytest --html report/report.html --self-contained-html
(2)pytest.ini文件:addopts = pytest --html report/report.html --self-contained-html
注:默认情况下生成的 html 报告中 css 是分开的,分享报告时将无法正确展示样式,可以使用 --self-contained-html 将 css 合并到 html 中。
二、allure-pytest 生成 Allure 测试报告
Allure 框架是一个灵活的轻量级多语言测试报告工具,它不仅以 Web 的方式展示了简介的测试结果,而且允许参与开发过程的每个人从日常执行的测试中最大限度的提取有用信息。
从 dev/qa 的角度来看,Allure 报告简化了常见缺陷的统计:失败的测试可以分为 bug和被中断的测试,还可以配置日志、步骤、fixture、附件、计时、执行历史以及与TMS和BUG管理系统集成,所以,通过以上配置,所有负责的开发人员和测试人员可以尽可能的掌握测试信息。
从管理者的角度来看,Allure 提供了一个清晰的“大图”,其中包括已覆盖的特性、缺陷聚集的位置、执行时间轴的外观以及许多其他方便的事情。Allure 的模块化和可扩展性保证了您总是能够对某些东西进行微调,使 Allure 更适合您,那么今天我们就来说说如何使报告更加详细的显示我们需要的信息,以及 Allure 与 Jenkins 的集成。
要生成一份完整的 Allure 测试报告,需要先安装 Allure 命令行工具,然后找到数据生成测试报告。
1
安装
需安装 Allure 命令行工具以及 alluer-pytest 插件
安装 Allure:windows 下进入 https://bintray.com/qameta/maven/allure2 下载 Allure 的zip安装包解压,添加 allure(\安装路径\bin)到环境变量 path ;使用 allure --version 查看安装版本
源码:https://github.com/allure-framework/allure2
安装 alluer-pyt