Pytest使用pytest-html和allure生成测试报告

2022-12-01,,,

Pytest-html

1、安装命令pip3 install pytest-html,如下图:

  执⾏后,会在当前⽬录下⽣成 ⼀个report.html的⽂件,打开后会展示详细的测试报告,执行该命令python -m pytest tests/ --html=report/index.html

将会在report文件夹下生成index.html报告。

2、pytest-rerunfailures

  对执行失败的再次执行。安装命令pip3 install pytest-rerunfailures,安装如下图:

3、pip3 install -U pytest升级版本

  为了是测试报告看起来更加的舒适,我们需要安装allure-2.7.0,将解压好的allure-2.7.0文件夹(解压后里面有两个文件夹)下的bin打开,复制路径,

在此电脑的属性中选择高级系统设置配置环境变量,再选择Administrator的用户变量下选择Path,将文件路径粘贴。

  在cmd中执行allure检测安装是否成功,如图安装成功

再执行以下命令:

python -m pytest tests --alluredir=report/result(result下生成json的文件)

allure generate report/result/ -o report/html --clean (report下生成html的目录,里面包含了html的测试报告)

allure serve report/result(启动allure的服务,自动打开测试报告)

将会生成一个完美的测试报告,如下图:

Pytest使用pytest-html和allure生成测试报告的相关教程结束。

《Pytest使用pytest-html和allure生成测试报告.doc》

下载本文的Word格式文档,以方便收藏与打印。