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
