1

I have a bunch of tests running in Pytest that depend on a series of tests running in a class. I'm using pytest-dependency to run some other tests in another module, but only if all the tests in this dependency class pass.

This is the set of tests that absolutely NEED to pass for me to proceed with the rest of the tests. It has two methods inside the class:

@pytest.mark.dependency()
class TestThis:
    """Test steady state of network."""

    @pytest.mark.parametrize("device", params_this)
    def test_that(self, device: str) -> None:
        do something
        assert xyz == abc

    @pytest.mark.parametrize("device", params_that)
    def test_this_as_well(self, device: str) -> None:
        do something
        assert xyz == abc

Now, when I add only one dependency marker in the tests that follow, it works as expected. If any of the tests in TestThis::test_that fail, the rest of the tests are skipped.

@pytest.mark.dependency(
    depends=instances(

            "tests/test_xyz.py::TestThis::test_that",
            params_this,
        ),
    scope="session",
)
class TestEverything:
    """Class to test everything."""

However, when I add two dependency markers like below, the tests proceed as usual even if one or more of the tests within the dependencies fail. This is unexpected behavior AFAIK.

@pytest.mark.dependency(
    depends=instances(

            "tests/test_xyz.py::TestThis::test_that",
            params_this,
        ),
    scope="session",
)
@pytest.mark.dependency(
    depends=instances(

            "tests/test_xyz.py::TestThis::test_this_as_well",
            params_that,
        ),
    scope="session",
)
class TestEverything:
    """Class to test everything."""

Looking for possible solutions to this problem, because I cannot combine the two dependency methods into one for the rest of my test-suite to consume.

MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46
  • An update to this; I found that if a test fails from the test_that method, but the tests from test_this_as_well all pass, it proceeds with the test in the Test Everything method. But if tests in the second dependency marker fail, it skips the tests as expected. Need to figure out what the solution for this is. – Michael Scott Apr 02 '20 at 03:11

0 Answers0