目录
1、前言
有时候我们测试执行由于某些原因失败了,想要多执行几次,Pytest
可以使用pytest-rerunfailures
插件来实现。
安装方式:pip install pytest-rerunfailures
2、使用
(一)命令行或main函数中使用
pytest -v -s ./xxx.py --reruns 2
pytest.main(["-v","-s","xxx.py","--reruns=2"])
(二)全局配置中使用(推荐用法)
在pytest.ini
配置文件中addopts
添加reruns
参数
[pytest]
addopts = -s -v --reruns 2 --reruns-delay 2
testpaths = scripts
python_files = test_*.py
python_classes = Test*
python_functions = test*
说明:
--reruns 2
代表重跑次数
--reruns-delay 2
代表重跑间隔,单位秒
示例:
def test_1():
print("测试1")
assert True
def test_2():
print("测试2")
assert False
def test_3():
print("测试3")
assert True
"""
执行结果
mark/reruns/reruns.py::test_1 测试1
PASSED
mark/reruns/reruns.py::test_2 测试2
RERUN
mark/reruns/reruns.py::test_2 测试2
RERUN
mark/reruns/reruns.py::test_2 测试2
FAILED
mark/reruns/reruns.py::test_3 测试3
PASSED
"""
标签:reruns,14,--,py,pytest,重试,Pytest,测试,test
From: https://www.cnblogs.com/qishuaiRisen/p/16608156.html