-
Notifications
You must be signed in to change notification settings - Fork 40
Description
the link: https://pytest-dependency.readthedocs.io/en/stable/scope.html#explicitely-specifying-the-scope.
test_mod_01.py
import pytest
@pytest.mark.dependency()
def test_a():
print("test_a")
pass
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_b():
print("test_b")
assert False
@pytest.mark.dependency(depends=["test_a"])
def test_c():
print("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():
print("test_a")
assert False
@pytest.mark.dependency(
depends=["tests/test_mod_01.py::test_a", "tests/test_mod_01.py::test_c"],
scope='session'
)
def test_e():
print("test_e")
pass
@pytest.mark.dependency(
depends=["tests/test_mod_01.py::test_b", "tests/test_mod_02.py::test_e"],
scope='session'
)
def test_f():
print("test_f")
pass
@pytest.mark.dependency(
depends=["tests/test_mod_01.py::TestClass::test_b"],
scope='session'
)
def test_g():
print("test_g")
pass
"E:\Program Files\Python37\python.exe" "E:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_jb_pytest_runner.py" --path E:/PycharmProjects/SelniumPOM-master/tests/test_mod_02.py
Testing started at 19:23 ...
Launching pytest with arguments E:/PycharmProjects/SelniumPOM-master/tests/test_mod_02.py --no-header --no-summary -q in E:\PycharmProjects\SelniumPOM-master\tests
============================= test session starts =============================
collecting ... collected 4 items
test_mod_02.py::test_a XFAIL (deliberate fail) [ 25%]test_a
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_a():
print("test_a")
assert False
E assert False
test_mod_02.py:7: AssertionError
test_mod_02.py::test_e SKIPPED (test_e depends on tests/test_mod_01....) [ 50%]
Skipped: test_e depends on tests/test_mod_01.py::test_a
test_mod_02.py::test_f SKIPPED (test_f depends on tests/test_mod_01....) [ 75%]
Skipped: test_f depends on tests/test_mod_01.py::test_b
test_mod_02.py::test_g SKIPPED (test_g depends on tests/test_mod_01....) [100%]
Skipped: test_g depends on tests/test_mod_01.py::TestClass::test_b
======================== 3 skipped, 1 xfailed in 0.07s ========================
Process finished with exit code 0
the expect result is test_e and test_g is success!