Pytest 失败重运行机制


第一种:对所有用例使用
1、安装:pip install pytest-rerunfailures
2、命令行参数: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","--alluredir=../OutPuts/allure-results"]) pytest中的失败截图。
第二种:只对部分用例使用重运行机制
1、安装:pip install flaky

在指定的用例使用装饰器 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_example():     import random     assert random.choice([True, False])
reruns=5, reruns_delay=2:最多失败重跑5次 & 如果失败则延迟1秒后重跑(可以不传)
@flaky(max_runs=3, min_passes=2):第一次执行失败了,将会再次重复执行它3次,如果这3次中有2次成功了,则认为这个测试通过了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM