失败重跑
前言
在进行自动化测试的过程中,我们一定会有这样的需求:希望失败的用例可以自动重跑
在pytest中,提供了pytest-rerunfailures插件可以实现自动重跑的效果
前提条件
- Python 3.6,最高 3.10,或 PyPy3
- pytest 5.3 或更高版本
插件安装
pip3 install pytest-rerunfailures -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
使用前了解
命令行参数:--reruns n
(重新运行次数),--reruns-delay m
(等待运行秒数)
装饰器参数:reruns=n
(重新运行次数),reruns_delay=m
(等待运行秒数)
使用实例
重新运行所有失败的用例
如果需要把所有失败的用例都重新运行,使用 --reruns 命令,并且制定要运行的最大次数,举个🌰:
# FileName: test_03.py
class TestDemo:
def setup(self):
print("执行setup method方法")
def teardown(self):
print("执行teardown方法")
def