httprunner 3.x学习6

前言

HttpRunner 3.x版可以使用所有的 pytest 插件,包括测试报告插件,像的 pytest-html 和 allure-pytest 。

pytest-html

httprunner 安装的时候,会自动安装 pytest 和 pytest-html 插件,对应的版本号是

  • pytest 5.4.3
  • pytest-html 2.1.1
C:Usersdell>pip show pytest
Name: pytest
Version: 5.4.3

C:Usersdell>pip show pytest-html
Name: pytest-html
Version: 2.1.1

hrun 生成报告

hrun 命令生成报告的时候,带上 --html 指定报告路径

>hrun testcases/login_userinfo_test.py --html=./reports/result.html

--html 参数生成的报告,css文件是单独分开的,不方便查看,可以加上--self-contained-html参数让css文件集成到html上

>hrun testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html

运行结果

查看html报告

pytest 生成报告

用 hrun 运行生成的报告会出现一大堆的报错: OSError: [WinError 6] 句柄无效。并且无法显示 request 和 response 内容。
hrun 执行pytest用例还不太完善,尽量用pytest去执行py脚本

>pytest testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html

执行后查看报告

allure 报告

httprunner3 也可以支持 allure 插件,需 pip 安装

> pip install allure-pytest

相关教程看这篇https://www.cnblogs.com/yoyoketang/p/12004145.html

原文地址:https://www.cnblogs.com/yoyoketang/p/14890723.html