小工具知识网

当前位置: 首页 > 行业知识 > python——pytest对于失败的用例重新执行

行业知识

python——pytest对于失败的用例重新执行

2026-12-04 04:19:17 来源:互联网转载

python pytest���动化测试时,对于失败的用例可以重跑,这就避免了偶然性fail的影响

()

安装:

1、pip install pytest-rerunsfailures

()

2、如果需要html的测试报告,需要安装:pip install pytest-html

三种方式:

方法1:在python自动化项目根目录下新建pytest.ini,在配置文件中写入以下内容:

[pytest]addpots = -vs --reruns 1 --reruns-delay 60

        其中:reruns为失败用例重跑的次数(此处为1次,也可以为2、3次),reruns-delay为间隔时间,单位为s

方法2:在想要重跑的用例前加上@pytest.mark.flaky(reruns=2,reruns-delay=2)

方法3:命令行参数:pytest --reruns 重试次数(--reruns-delay 次数之间间隔)

pytest --reruns 2 运行失败的用例可以执行2次pytest --reruns 2 --reruns-delay5 运行失败的用例可以执行2次,每次间隔5s

上一篇:监控服务器故障怎么解决?

下一篇:微信自转账全攻略,轻松掌握个人转账操作技巧