pytest执行用例失败重试插件的使用
pytest-rerunfailures
pytest-rerunfailures是属于pytest的插件,通常用来执行用例失败后重新执行。
安装:pip install pytest-rerunfailures
如果运行报错, 则使用python编辑器重新安装
1. 通过装饰器使用:@pytest.mark.flaky(reruns=3, reruns_delay=2)
import pytest class Test01: @pytest.mark.flaky(reruns=3, reruns_delay=2) # 执行失败后重试, 重试3次,每次重试间隔2秒 def test_01(self): print('---用例01---') assert 1 == 2 def test_02(self): print('---用例02---') assert 1 == 1 if __name__ == '__main__': pytest.main(['-s','test_001file.py'])
2. 也可以装饰在类中
import pytest @pytest.mark.flaky(reruns=3, reruns_delay=2) # 执行失败后重试, 重试3次,每次重试间隔2秒 class Test01: def test_01(self): print('---用例01---') assert 1 == 2 def test_02(self): print('---用例02---') assert 1 == 1 if __name__ == '__main__': pytest.main(['-s','test_001file.py'])
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具