Skipped testcases while using pytest-dependency across modules

95 views Asked by At

Been learning Pytest recently and got stuck with the sample code from the documentation. Just made a few changes on the code with the aim of making all testcases pass but looks like the one's with dependency from test_mod_01 tend to be skipped. Not sure where I doing wrong

Code Structure

  TestOrderDependencies
        -- test_mod_01.py
        -- test_mod_02.py

test_mod_01.py

import pytest


@pytest.mark.dependency(name="a")
def test_a():
    pass


@pytest.mark.dependency(name="b")
# @pytest.mark.xfail(reason="deliberate fail")
def test_b():
    assert True


@pytest.mark.dependency(name="c", depends=["a"])
def test_c():
    pass


class TestClass(object):

    @pytest.mark.dependency(name="b", depends=["c"])
    def test_b(self):
        pass

test_mod_02.py

import pytest


@pytest.mark.dependency(name="a")
# @pytest.mark.xfail(reason="deliberate fail")
def test_a():
    assert True


@pytest.mark.dependency(name="e",
                        depends=["TestOrderDependencies/test_mod_01.py::a",
                                 "TestOrderDependencies/test_mod_01.py::c"],
                        scope='session'
                        )
def test_e():
    pass


@pytest.mark.dependency(name="f",
                        depends=["TestOrderDependencies/test_mod_01.py::b",
                                 "TestOrderDependencies/test_mod_02.py::e"],
                        scope='session'
                        )
def test_f():
    pass


@pytest.mark.dependency(name="g",
                        depends=["TestOrderDependencies/test_mod_01.py::TestClass::b"],
                        scope='session'
                        )
def test_g():
    pass

Output

rootdir: /Users/xxxx/PycharmProjects/TestOrderDependencies
plugins: order-1.2.0, dependency-0.5.1
collected 8 items                                                                                                                                                                                                                 

test_mod_01.py::test_a PASSED
test_mod_01.py::test_b PASSED
test_mod_01.py::test_c PASSED
test_mod_01.py::TestClass::test_b PASSED
test_mod_02.py::test_a PASSED
test_mod_02.py::test_e SKIPPED (test_e depends on TestOrderDependencies/test_mod_01.py::a)
test_mod_02.py::test_f SKIPPED (test_f depends on TestOrderDependencies/test_mod_01.py::b)
test_mod_02.py::test_g SKIPPED (test_g depends on TestOrderDependencies/test_mod_01.py::TestClass::b)

================================================================================================== 5 passed, 3 skipped in 0.03s ====
  1. I have tried to look at similar situation here and followed the suggestions
  2. Also tried utilizing pytest-order.
  3. Tried to downgrade my python from 3.11 - 3.10.

With these attempts i could not make it work. Thanks in advance.

0

There are 0 answers