In pytest-dependency, is there a way to execute tests only if all of multiple parametrized test cases pass?

779 views Asked by At

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.

0

There are 0 answers