测试报告
受益于pytest的集成,HttpRunner v3.x可以利用pytest所有插件,包括pytest-html
和allure-pytest
内置html报告
pytest-html
插件随HttpRunner一期安装。当你运行测试用例想生成html报告时,可以在命令行中添加--html
$ hrun /path/to/testcase --html=report.html
如果想创建一个独立的、更加方便共享测试结果的html报告,可以在命令行中添加--self-contained-html
$ hrun /path/to/testcase --html=report.html --self-contained-html
详情请看pytest-html
allure报告
allure-pytest
是HttpRunner的可选依赖项,所以如果想生成allure报告时,需要单独安装:
pip install allure-pytest
或者在安装httprunner时选择安装:
pip install "httprunner[allure]"
一旦allure-pytest
安装好,可以用hrun/pytest
使用如下功能:
* --alluredir = DIR
:在指定目录中生成“魅力”报告(可能不存在)
* --clean-alluredir
:清理alluredir文件夹(如果存在)
* --allure-no-capture
:不要将pytest捕获的日志记录/ stdout / stderr附加到报告中
要使Allure侦听器能够在测试执行期间收集结果,只需添加--alluredir选项,并提供指向应存储结果的文件夹的路径。 例如。:
$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results
注意:这里需要安装allure ,并配置系统环境变量 要在测试完成后查看实际报告,您需要使用Allure命令行实用程序从结果生成报告。
# 在线打开报告
$ allure serve /tmp/my_allure_results
# 生成html报告
allure generate reports/allure -o reports/allure/html
此命令将在默认浏览器中显示您生成的报告 详情请看:allure-pytest