Pytest系列(11)- 失败重跑插件pytest-rerunfailures详细使用
2024-09-26 16:47:30
如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
环境前提
以下先决条件才能使用pytest-rerunfailures
- Python 3.5, 最高 3.8, or PyPy3
- pytest 5.0或更高版本
安装插件
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 命令行选项,并指定要运行测试的最大次数:
pytest --reruns -s
知识点
运行失败的fixture或setup_class也将重新执行
添加重新运行的延时
要在两次重试之间增加延迟时间,使用 --reruns-delay 命令行选项,指定下次测试重新开始之前等待的秒数
pytest --reruns --reruns-delay -s
重新运行指定的测试用例
要将单个测试用例添加flaky装饰器 @pytest.mark.flaky(reruns=5) ,并在测试失败时自动重新运行,需要指定最大重新运行的次数
小栗子
import pytest @pytest.mark.flaky(reruns=5)
def test_example():
import random
assert random.choice([True, False, False])
执行结果
collecting ... collected 1 item 11_reruns.py::test_example RERUN [100%]
11_reruns.py::test_example PASSED [100%] ========================= 1 passed, 1 rerun in 0.05s ==========================
同样的,这个也可以指定重新运行的等待时间
@pytest.mark.flaky(reruns=5, reruns_delay=2)
def test_example():
import random
assert random.choice([True, False, False])
注意事项
如果指定了用例的重新运行次数,则在命令行添加--reruns对这些用例是不会生效的
兼容性问题
- 不可以和fixture装饰器一起使用: @pytest.fixture()
- 该插件与pytest-xdist的 --looponfail 标志不兼容
- 该插件与核心--pdb标志不兼容
最新文章
- Linux模块编程框架
- WPF入门教程系列十九——ListView示例(一)
- Razor练习1
- Loadrunner11.0 录制手机App脚本的方法
- JDBC中的PreparedStatement
- sql if
- LeetCode (10): Regular Expression Matching [HARD]
- Visual studio 内存不足的解决方案(out of memory)
- C++第15周(春)项目3 - OOP版电子词典(一)
- Android WebView 小结
- STM32 + RT Thread OS 学习笔记[二]
- Docker镜像与容器命令(转)
- 无法启动此程序因为计算机中丢失msvcr71
- 读书笔记之《深入理解Java虚拟机》不完全学习总结
- 在IntelliJ IDEA里创建简单的基于Maven的SpringMVC项目
- Springboot项目配置druid数据库连接池,并监控统计功能
- vue在jsx中使用for循环
- 大学jsp实验3include指令的使用
- Python 装饰器(笔记,非原创)
- 深入SpringBoot:自定义Endpoint(转)
热门文章
- [android]R.class里有ID,onCreate方法里调用findViewById返回空
- Vue2.0 【第一季】第2节 v-if v-else v-show 指令
- 一个交互式可视化Python库——Bokeh
- Java第一节课考试
- dom4j解析xml格式文件实例
- Linux命令进阶篇-文件查看与查找
- 让 Linux 防火墙新秀 nftables 为你的 VPS 保驾护航
- AndroiBugs Android漏洞扫描器
- priority_queue 中存放pair时,自定义排序的写法
- [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)