pytest详解-(3)插件

  • pip install pytest        # 安装pytest
  • pip install pytest-html           #生成html报告
    • pytest --html=path/to/html/report.html;如果不添加--self-contained-html参数,生成报告的css文件是独立的,分享的时候容易数据丢失 
  • pip install pytest-rerunfailures  # 失败后重跑
    • 命令行参数:pytest -- reruns 重试次数 (--reruns-delay 次数之间间隔)
    • pytest --reruns 2 运行失败的用例可以执行2次
    • pytest --reruns 2 --reruns-delay 5 运行失败的用例可以执行2次,每次间隔5秒
    • pytest.main(["-v","-m","demo","--reruns","2","--reruns-delay","5"])
  • pip install flaky                 # 只对部分用例使用重新运行机制
    • @pytest.mark.flaky(reruns=5, reruns_delay=2)
    • reruns=5, reruns_delay=2:最多失败重跑5次 & 如果失败则延迟1秒后重跑(可以不传)
    • @flaky(max_runs=3, min_passes=2):第一次执行失败了,将会再次重复执行它3次,如果这3次中有2次成功了,则认为这个测试通过了。
  • pip install allure-pytest        #通过allure生成报告
  • pip install pytest-xdist         #多个cpu并行执行用例,需要在pytest后添加参数-n,如果参数为auto,则会自动检测系统cpu个数。如果参数为数字,则指定运行测试用例的处理器进程数
    • demo:
      • pytest -n auto
      • pytest -n [num]
  • pip install PyYAML                # 把测试数据放在yaml文件
posted @ 2020-06-28 19:37  jaxon-chen  阅读(134)  评论(0)    收藏  举报