测试框架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

相关推荐
-森屿安年-10 分钟前
LeetCode 283. 移动零
开发语言·c++·算法·leetcode
寻找华年的锦瑟14 分钟前
Qt-FFmpeg案例(0基础,包含环境配置)
开发语言·qt·ffmpeg
用户7851278147015 分钟前
实战解析:淘宝/天猫商品描述API(taobao.item_get_desc)接口
python
codists18 分钟前
Pycharm错误:JetBrains AI URL resolution failure
python
tanxiaomi28 分钟前
Spring、Spring MVC 和 Spring Boot ,mybatis 相关面试题
java·开发语言·mybatis
浮尘笔记31 分钟前
Go并发编程核心:Mutex和RWMutex的用法
开发语言·后端·golang
青瓷程序设计35 分钟前
鱼类识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
散峰而望36 分钟前
C++数组(一)(算法竞赛)
c语言·开发语言·c++·算法·github
wjs20241 小时前
C++ 指针
开发语言
该用户已不存在1 小时前
Python正在死去,2026年Python还值得学吗?
后端·python