Python pytest增量示例代码如何跳过测试(pytest项和调用对象?)

Python pytest增量示例代码如何跳过测试(pytest项和调用对象?),python,pytest,increment,Python,Pytest,Increment,我试图找出pytest文档中使用增量标记跳过测试的示例代码是如何工作的,可以在“增量测试-测试步骤”下找到 我试图理解它是如何工作的,因为我想修改它,使其以稍微不同的行为运行 我的最终目标是修改代码,以便如果我有一个包含6个函数的类,例如,如果1失败,则执行类似于kip函数2和3的操作;如果4失败,则跳过5和6,但如果1失败,则不执行 底部的完整代码来自以下示例:允许您为测试函数或类添加pytest标记@pytest.mark.incremental。如果类中用增量标记标记的函数失败,则将跳过该

我试图找出pytest文档中使用增量标记跳过测试的示例代码是如何工作的,可以在“增量测试-测试步骤”下找到

我试图理解它是如何工作的,因为我想修改它,使其以稍微不同的行为运行

我的最终目标是修改代码,以便如果我有一个包含6个函数的类,例如,如果1失败,则执行类似于kip函数2和3的操作;如果4失败,则跳过5和6,但如果1失败,则不执行

底部的完整代码来自以下示例:允许您为测试函数或类添加pytest标记
@pytest.mark.incremental
。如果类中用增量标记标记的函数失败,则将跳过该类中所有其他函数

据我所知,每次运行测试函数时都会调用conftest.py文件中的代码。我认为
pytest\u runtest\u makereport
是在测试完成后运行的,不知何故,使用“exinfo”可以确定测试是否通过

我真的不知道以下几行是如何工作的:

  parent = item.parent
  parent._previousfailed = item
什么是
item
item.parent
?为什么将
parent.\u先前失败的
属性设置为

pytest\u runtest\u安装程序
检查
项。父项
是否具有此
\u先前失败的
属性,如果是,则测试失败

我不知道传递的项和调用参数是什么。我发现下面提到了项目类型,但并没有真正澄清太多

还有为什么调用
pytest\u runtest\u makereport
pytest\u runtest\u setup
函数。它们是pytest框架中的特殊“关键字”函数名吗

# content of conftest.py
import pytest


def pytest_runtest_makereport(item, call):
    if "incremental" in item.keywords:
        if call.excinfo is not None:
            parent = item.parent
            parent._previousfailed = item


def pytest_runtest_setup(item):
    if "incremental" in item.keywords:
        previousfailed = getattr(item.parent, "_previousfailed", None)
        if previousfailed is not None:
            pytest.xfail("previous test failed (%s)" % previousfailed.name)



# content of test_step.py

import pytest


@pytest.mark.incremental
class TestUserHandling(object):
    def test_login(self):
        pass

    def test_modification(self):
        assert 0

    def test_deletion(self):
        pass


def test_normal():
    pass