pytest plugin for controlling execution flow
Project description
What?
pytest-node-dependency is a pytest plugin that allows you to define dependencies between tests and reorder their execution based on those dependencies. This plugin ensures that tests with dependencies run after their required prerequisites have completed successfully.
How to install?
pip install pytest-node-dependency
How to use?
To set up a test dependency, decorate the test function with the depends
mark and provide a list of dependencies via the on
keyword argument to the decorator. Dependencies can be specified by name only when in the same file as the test being decorated or by the pytest node path for tests in other files/classes.
import pytest
def test_second(request):
print("second")
assert request.session.items[1].name == 'test_second'
@pytest.mark.depends(on=["test_plugin.py::test_second"])
def test_last(request):
print("last")
assert request.session.items[2].name == 'test_last'
def test_first(request):
print("first")
assert request.session.items[0].name == 'test_first'
Xdist adoption:
The way xdist plugin works is by utilizing multiple cores and spreads the tests among them. The problem with the plugin is that if you wish to use reordering, you probably want to set some dependency among the tests, However, the xdist plugin will break it.
For that, you should set the group for the tests. The group means that a gateway worker will collect the tests, and will place all the grouped tests in a single gateway worker. This will lead creation of serial testing among parallel exectuion.
import pytest
@pytest.mark.depends(xdist_group='a')
def test_second(request):
print("second")
assert request.session.items[1].name == 'test_second'
@pytest.mark.depends(on=["test_plugin.py::test_second"], xdist_group='a')
def test_last(request):
print("last")
assert request.session.items[2].name == 'test_last'
def test_first(request):
print("first")
assert request.session.items[0].name == 'test_first'
Limitations and known issues:
- All the tests without dependency (both dependent-on) will run first, then, all tests with connections will run (e.g. the list of items will be as described)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest-node-dependency-1.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8103fefeafde9ecc3108459ab47d11b69d211f124162b036e5a63b79fd679e2d |
|
MD5 | 321292c729d773f758139a97234113a5 |
|
BLAKE2b-256 | de2f34374f943f4e19a5c5e15a3c2d882f3e7159cde0c2542734e9574a7d25de |
Hashes for pytest_node_dependency-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf816d2e8eaaa180a496edacbaf8e7b15758ffd818cdbfd878eb5139d7ed05fc |
|
MD5 | 1e0e603a16889e0c9717a145c6ef418f |
|
BLAKE2b-256 | bc89ab505f9dfc4a32ee8a7d85c432d8af39bf4b98314b48539a597af1c392cc |