Search code examples
pythonpytestpytest-dependency

pytest dependency with unused marks


I have the following code:

@pytest.mark.dependency
@pytest.mark.test_a
def test_a():    
    <test>

@pytest.mark.dependency(depends=["test_a"], reason="Skipped since test_a failed")
@pytest.mark.test_b
def test_b():
    <test>

I have a python test file with 2 test inside: test_a & test_b test_b depended on test_a. Both test got a unique mark in order to run them as a single unit.

When I run it regularly without supplying any mark - all works ok.

python3 -m pytest

When I run with test_a mark - works ok:

python3 -m pytest -m test_a

But when I run with test_b mark, which should run only test_b without test_a, test_b skipped because of the dependency:

python3 -m pytest -m test_a

How can I make the dependency work only when the depended test actually ran?

Thanks, Avi


Solution

  • Have a look for cli option –ignore-unknown-dependency in https://pytest-dependency.readthedocs.io/en/stable/configuration.html.