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'])