I want to run some tests that depend on the sucess of other tests using pytest and pytest-dependency.
I have this directory structure:
root/ tests/ specs/ a_test.py b_test.py
The content of a_test.py:
import pytest
@pytest.mark.dependency()
def test_a():
assert 1
@pytest.mark.dependency()
def test_b():
assert 1
The content of b_test.py:
import pytest
test_dependencies = [
"tests/specs/a_test.py::test_a",
"tests/specs/a_test.py::test_b",
]
@pytest.mark.dependency(depends=test_dependencies, scope="session")
def test_c():
assert 1
To execute the tests , i run this command from the root directory : python -m pytest --rootdir=tests
My problem here is that dependencies (test_a and test_b) pass , but the dependent test (test_c) gets skipped
according to pytest-dependency's docs:
...
Note that the references in session scope must use the full node id of the dependencies. This node id is composed of the module path, the name of the test class if applicable, and the name of the test, separated by a double colon “::”
...
Any idea why it isn't working like it's supposed to ?
For future readers, in this quote :
...
Note that the references in session scope must use the full node id of the dependencies. This node id is composed of the module path, the name of the test class if applicable, and the name of the test, separated by a double colon “::”
...
The module path is relative to the --rootdir
parameter, so the test_dependencies should be :
test_dependencies = [
"specs/a_test.py::test_a",
"specs/a_test.py::test_b",
]
PS : After testing, it looks like pytest loads test modules (in the same directory at least) in alphabetical order, so you need to make sure that dependencies are loaded before the dependent tests.