I\'m working on a functional test suite using pytest with pytest-dependency. I 99% love these tools, but I can\'t figure out how to have a test in one file depend on a test
pytest-dependency==0.3.2
At the moment, pytest-dependency
does the dependency resolution on module level only. Although there is some rudimentary implementation for resolving session-scoped dependencies, the full support is not implemented at the moment of writing this. You can check that by slipping session scope instead of module scope:
# conftest.py
from pytest_dependency import DependencyManager
DependencyManager.ScopeCls['module'] = DependencyManager.ScopeCls['session']
Now test_two
from your example will resolve the dependency to test_one
. However, this is just a dirty hack for demonstration purposes that will easily corrupt the dependencies once you add another test named test_one
so read further.
There is a PR that adds the dependency resolution on session and class levels, but it's not accepted yet by the package maintainer. You can use that instead:
$ pip uninstall -y pytest-dependency
$ pip install git+https://github.com/JoeSc/pytest-dependency.git@master
Now the dependency
mark accepts an additional arg scope
:
@pytest.mark.dependency(scope='session')
def test_one():
...
You will need to use the full test name (as printed by pytest -v
) in order to depend on test_one
in another module:
@pytest.mark.dependency(depends=['test_one.py::test_one'], scope='session')
def test_two():
...
Named dependencies are also supported:
@pytest.mark.dependency(name='spam', scope='session')
def test_one():
...
@pytest.mark.dependency(depends=['spam'], scope='session')
def test_two():
...