web自动化中pytest框架的使用(三)---重运行机制和html报告生成

1、Pytest提供了失败重试机制:

插件名称:rerunfailures

安装方法:pip install pytest-rerunfailures

2、使用方式:

  命令行参数形式:

  命令:pytest --reruns 重试次数

  比如:pytest --reruns 2 表示:运行失败的用例可以重新运行2次

  命令:pytest --reruns 重试次数 --reruns-delay 次数之间的延时设置(单位:秒)

  比如:pytest --reruns 2 --reruns-delay 5 表示失败的用例可以重新运行2次,第一次和第二次的间隔时间为5秒钟

3、输出代码中的prient信息,需要使用pytest -s可以输出prient信息 

4、pytest-html报告

  pytest可以生成多种样式的结果:

    1、生成junitXML格式的测试报告:命令:--junitxml=path(只能是相对路径)

    2、生成result log格式的测试报告:命令:--resultlog=reportlog.txt

    3、生成Html格式的测试报告:命令:--html=report est_one_func.html

     备注:pytest-html中生成测试报告使用的路径只能是当前项目的相对路径

  使用命令:

pytest -m one -s --reruns 2 --reruns-delay 5 --junitxml=Outputs/test_result/html_result/login_test_result.xml --html=Outputs/test_result/html_result/login_result.html

可以生成 xml 和 html 的测试报告

原文地址:https://www.cnblogs.com/wsk1988/p/12779736.html