pytest快速入门(6)--重运行机制

pytest相较于unittest,提供了失败重运行机制。一旦测试用例运行失败,可以马上进行重运行。

在使用pytest的失败重运行机制前,需要安装相应的插件:

插件名称:rerunfailures

安装方法:pip install pytest-rerunfailures

使用方式:

方式一:

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

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

方式二:使用主函数main.py执行

  pytest.main(["reruns","2","--reruns-delay","5"])  

原文地址:https://www.cnblogs.com/yif930916/p/14791779.html