测试框架pytest教程(5)运行失败用例-rerun failed tests

python 复制代码
# content of test_50.py
import pytest


@pytest.mark.parametrize("i", range(50))
def test_num(i):
    if i in (17, 25):
        pytest.fail("bad luck")

运行这个文件,2个失败,48个通过。

要运行上次失败的测试用例,可以使用--lf(或--last-failed)选项来告诉pytest只运行上次运行时失败的测试。

运行上次失败用例--lf/--last-failed

命令行示例:

复制代码
pytest --lf

或者在pytest配置文件(比如pytest.ini)中设置:

复制代码
[pytest]
addopts = --lf

这样,pytest会检测上次运行时失败的测试用例,并只运行这些失败的用例,以便进行重新运行、调试或验证失败修复。

先运行上次失败用例再运行成功用例--ff/--failed-first

复制代码
pytest --ff

先运行新的用例--nf/``--new-first

相关推荐
一方热衷.24 分钟前
YOLO26-Seg ONNXruntime C++/python推理
开发语言·c++·python
YMWM_2 小时前
如何将包路径添加到conda环境lerobot的python路径中呢?
人工智能·python·conda
靓仔建2 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
田里的水稻2 小时前
ubuntu22.04_openclaw_ROS2
人工智能·python·机器人
梁正雄2 小时前
Python前端-2-css练习
前端·css·python
wefly20173 小时前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
赶路人儿3 小时前
UTC时间和时间戳介绍
java·开发语言
6+h3 小时前
【java】基本数据类型与包装类:拆箱装箱机制
java·开发语言·python
GDAL3 小时前
MANIFEST.in简介
linux·服务器·前端·python
MoRanzhi12034 小时前
pillow 图像合成、透明叠加与蒙版处理
python·计算机视觉·pillow·图片处理·图像合成·透明叠加·多图层叠加