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'])
复制代码

 

posted @   博无止境  阅读(164)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示