官方的代码

# test1.py
import pytest


@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_a():
    assert False


@pytest.mark.dependency()
def test_b():
    pass


@pytest.mark.dependency(depends=["test_a"])
def test_c():
    pass


@pytest.mark.dependency(depends=["test_b"])
def test_d():
    pass


@pytest.mark.dependency(depends=["test_b", "test_c"])
def test_e():
    pass


↙↙↙阅读原文可查看相关链接,并与作者交流