httprunner v3.x 官方教程中文翻译06--Testing Report(测试报告)

测试报告

得益于与pytest的集成,HttpRunner v3.5可以使用所有的pytest插件,包括测试报告插件,如pytest-htmlallure-pytest

pytest html

pytest-html插件附带HttpRunner安装。当您想为testcase执行生成一个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 report

allure report是HttpRunner的一个可选依赖项,因此如果您想生成allure报告,应该单独安装allure report插件。

$ pip3 install "allure-pytest"

或者您可以安装带有allure额外包的HttpRunner。

$ pip3 install "httprunner[allure]"

一旦allure-pytest准备好了,以下参数可以与hrun/pytest命令一起使用。

  • --alluredir=DIR:在指定目录中生成Allure报告(可能不存在)
  • --clean-alluredir:清理alluredir文件夹,如果存在的话
  • --allure-no-capture:不要将pytest捕获的日志/stdout/stderr附加到报告中

要使Allure listener能够在测试执行期间收集结果,只需添加 --alluredir选项并提供存储结果的文件夹的路径。例如:

$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results

要在测试完成后查看实际的报告,需要使用Allure命令行实用程序从结果生成报告。

$ allure serve /tmp/my_allure_results

此命令将在默认浏览器中显示生成的报告。

您可以参考allure-pytest了解更多细节。

原文地址:https://www.cnblogs.com/yywmz/p/14030070.html