参考从pytest-dependency复制的示例代码,通过删除“tests”文件夹进行轻微更改,我希望“test_e”和“test_g”通过,但是,两者都被跳过。请告知我是否做了任何愚蠢的事情来阻止会话范围正常工作。
笔记:
- 使用 pytest-dependency 0.5.1。
- 两个模块分别相对于当前工作目录存储。
test_mod_01.py
import pytest
@pytest.mark.dependency()
def test_a():
pass
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_b():
assert False
@pytest.mark.dependency(depends=["test_a"])
def test_c():
pass
class TestClass(object):
@pytest.mark.dependency()
def test_b(self):
pass
test_mod_02.py
import pytest
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_a():
assert False
@pytest.mark.dependency(
depends=["./test_mod_01.py::test_a", "./test_mod_01.py::test_c"],
scope='session'
)
def test_e():
pass
@pytest.mark.dependency(
depends=["./test_mod_01.py::test_b", "./test_mod_02.py::test_e"],
scope='session'
)
def test_f():
pass
@pytest.mark.dependency(
depends=["./test_mod_01.py::TestClass::test_b"],
scope='session'
)
def test_g():
pass
意外输出
=========================================================== test session starts ===========================================================
...
collected 4 items
test_mod_02.py xsss
[100%]
====================================================== 3 skipped, 1 xfailed in 0.38s ======================================================
预期产出
=========================================================== test session starts ===========================================================
...
collected 4 items
test_mod_02.py x.s.
[100%]
====================================================== 2 passed, 1 skipped, 1 xfailed in 0.38s ======================================================