6、pytest生成html报告

156 阅读1分钟

前言:

在使用pytest做一些自动化测试的时候,我们经常需要一些测试报告来做测试统计,那么使用pytest如何生成测试报告呢?pytest给我们提供了很多的第三方的测试报告插件,常见的有:

pytest-html

allure-pytest

pytest-tmreport

本轮先学习pytest-html

1、report文件夹专门来存放测试报告 2、执行pytest --html report/report.html 3、用浏览器打开report.html,如下图所示 虽然有点一言难尽,但是确实该有的都有了,可以看到最上面有环境的信息,有整体的测试汇总结果,勉强可以看看

image.png 我们也可以在pytest.ini配置生成测试报告

[pytest]

addopts = -vs  --html report/report1.html
testpaths =./test_testcase
python_files =   test_first.py
python_classes =   Test*   test*
python_functions = test_*  test*

执行后如下图所示

image.png