测试框架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 小时前
东华OJ-进阶题-19-排队打水问题(C++)
开发语言·c++·算法
前进的李工10 小时前
LangChain使用之Model IO(提示词模版之PromptTemplate)
开发语言·人工智能·python·langchain
Storynone10 小时前
【Day27】LeetCode:56. 合并区间,738. 单调递增的数字
python·算法·leetcode
superkcl202210 小时前
C++初始化列表
开发语言·c++
biter down10 小时前
C++设计一个不能被拷贝的特殊类
开发语言·c++
似水明俊德10 小时前
10-C#
开发语言·windows·c#
似水明俊德10 小时前
14-C#
开发语言·c#
勇敢牛牛_10 小时前
【aiway】基于 Rust 开发的 API + AI 网关
开发语言·后端·网关·ai·rust
叶子20242211 小时前
承认错误才能成长
python
khddvbe11 小时前
C++中的代理模式实战
开发语言·c++·算法