Can't Make Pytest Dependency Work For Different Modules

- 1 answer

Following this answer and the doc, I am trying to make tests depend on each other between files:

@pytest.mark.dependency(depends=[""], scope="session")
def test_aaa():
    assert False

@pytest.mark.dependency(depends=["tests/"], scope="session")
def test_bbb():
    assert False

@pytest.mark.dependency(depends=["atp/tests/"], scope="session")
def test_ccc():
    assert False


def test_sssss():
    assert True

The folder structure:



> ssh://[email protected]:port~/src/uv-fleet-atp/venv/bin/python -u ~/.pycharm_helpers/pycharm/ --path ~/src/uv-fleet-atp/atp/tests
============================= test session starts ==============================
collected 4 items                                                       SKIPPED (test_aaa depends on test_ser...)
Skipped: test_aaa depends on SKIPPED (test_bbb depends on tests/te...)
Skipped: test_bbb depends on tests/ SKIPPED (test_ccc depends on atp/test...)
Skipped: test_ccc depends on atp/tests/ PASSED

========================= 1 passed, 3 skipped in 0.35s =========================

How to not skip dependent tests?



As mentioned in the comments, pytest-dependency does not order tests, it relies on the tests executed in the correct order for dependencies to work. The reasoning behind this is that pytest-dependency is thought to do one thing and one thing only, which is to skip tests depending on the test relationships. Ordering can either be done manually by arranging the tests accordingly (e.g. adapt the names, what most users seem to do), or rely on an ordering plugin. There has been a controversial discussion about this, and certainly not everyone agrees with that philosophy (I tend to agree), but in the end it is the prerogative of the plugin author to decide.

pytest-order works together with pytest-dependency. If it is installed and you run your tests with the option --order-dependencies it will order your tests with dependency markers if needed. As usual, you can instead add the option to pytest.ini:

; always order tests with dependency markers
addopts = --order-dependencies

As for tests that cannot be found, it should issue a respective warning.

I'm the maintainer of pytest-order.