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.
A unique feature of the plugin is that if you set a test to depend on another one, the plugin will check if the test being depended upon failed. If that's the case, it will mark the current test as 'expected to fail' (xfail).
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)
- Currently, automated xfail is enabled, it should be configurable.
Release files for pytest-node-dependency 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-node-dependency-1.4.0.tar.gz | 5.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_node_dependency-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / pytest-node-dependency-1.4.0.tar.gz
| Download URL | pytest-node-dependency-1.4.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1aa3fe11a08edff02d0c86d5ce5302aa0ffd8477164f5cb39d4dbfee81508642
|
|
BLAKE2b-256 checksum How to use checksums |
3cebd97625c9c64d9e0daa609971e4cc9b348be9580d838ee9a60cd541a085db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Release files / pytest_node_dependency-1.4.0-py3-none-any.whl
| Download URL | pytest_node_dependency-1.4.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6775d4ea885d02714e56285a78d403009bcf3949ad3ac9edad0cab9a299e258a
|
|
BLAKE2b-256 checksum How to use checksums |
1c4c4e7eeb9c3de52a0801953aa1a5eff798cc4bbaae88b9aeedefe11cf86d83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|