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

相关推荐
another heaven5 小时前
【Qt VS2022调试时无法查看QString等Qt变量信息】解决方法
开发语言·qt
A黄俊辉A5 小时前
axios+ts封装
开发语言·前端·javascript
Y学院5 小时前
Python 数据分析:从新手到高手的“摸鱼”指南
python·数据分析
杨福瑞5 小时前
C语⾔内存函数
c语言·开发语言
深耕AI5 小时前
【PyTorch训练】准确率计算(代码片段拆解)
人工智能·pytorch·python
eqwaak05 小时前
科技信息差(9.12)
开发语言·python·科技·量子计算
axban6 小时前
QT M/V架构开发实战:QStringListModel介绍
开发语言·数据库·qt
刘媚-海外6 小时前
Go语言开发AI应用
开发语言·人工智能·golang·go
Blossom.1186 小时前
从“能写”到“能干活”:大模型工具调用(Function-Calling)的工程化落地指南
数据库·人工智能·python·深度学习·机器学习·计算机视觉·oracle