Registry / testing / pytest-dependency

pytest-dependency

JSON →
library0.6.1pypypi✓ verified 25d ago

pytest-dependency is a plugin for the pytest Python testing framework that allows you to manage dependencies between tests. Tests marked as dependent on others will be automatically skipped if any of their dependencies fail or are skipped. The current version is 0.6.1, released in February 2026, and the project maintains an active, albeit irregular, release cadence.

pip install pytest-dependency
INSTALL
IMPORT
SIG · PYTEST-DEPENDENCY
P
pytest-dependency
testingpythonv0.6.1
Install
3.9s avg
Import
406ms
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.422s · 32.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.9s · import 0.390s · 33MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

depends
from pytest_dependency import depends
import pytest
DependencyManager
from pytest_dependency import DependencyManager
DependencyItemStatus
from pytest_dependency import DependencyItemStatus

This example demonstrates basic test dependency management. `test_a` is marked to deliberately fail. `test_c` depends on `test_a` and will be skipped. `test_e` depends on both `test_b` (which passes) and `test_c` (which is skipped), leading to `test_e` also being skipped.

import pytest @pytest.mark.dependency() @pytest.mark.xfail(reason="deliberate fail", raises=AssertionError) def test_a(): assert False @pytest.mark.dependency() def test_b(): assert True @pytest.mark.dependency(depends=["test_a"]) def test_c(): assert True @pytest.mark.dependency(depends=["test_b"]) def test_d(): assert True @pytest.mark.dependency(depends=["test_b", "test_c"]) def test_e(): assert True # To run this, save as `test_deps.py` and run `pytest -rsx test_deps.py`
pytest --version
Debug
Known issues
breakingVersion 0.6.0 (released Dec 2023) dropped support for Python 2. Ensure your test environment uses Python 3.
fix
Upgrade your Python environment to Python 3.x if you are still on Python 2.x.
affects: >=0.6.0
breakingVersion 0.5.0 (released Feb 2020) requires `pytest` version 3.7.0 or newer. Older `pytest` versions are incompatible.
fix
Upgrade `pytest` to version 3.7.0 or newer using `pip install --upgrade pytest`.
affects: >=0.5.0
breakingVersion 0.3 (released Dec 2017) changed the default naming convention for test methods within test classes. The class name is now prepended to the method name to form the default test name. If you were relying on default names for dependencies of class methods in older versions, you may need to update your `depends` references.
fix
If referencing test methods by their default names in `depends`, prepend the class name (e.g., `Classname::test_method`). Alternatively, use the `name` argument in `pytest.mark.dependency(name='custom_name')` for explicit naming.
affects: >=0.3
gotcha`pytest-dependency` is incompatible with `pytest-xdist` when parallelization is enabled, as dependencies assume a sequential execution order. Tests may fail or be skipped incorrectly in parallel runs.
fix
Do not use `pytest-xdist`'s parallelization features (e.g., `-n`) when using `pytest-dependency`. If parallelization is critical, consider refactoring tests to be independent or exploring alternative dependency management strategies.
affects: All
gotchaTest names in `depends` lists must precisely match the registered test names. For parameterized tests or tests within classes, this often means using the full `pytest` node ID (e.g., `module.py::TestClass::test_method[param]`) or explicitly assigning a `name` via `@pytest.mark.dependency(name='my_test_name')`.
fix
Use explicit `name` arguments for `pytest.mark.dependency` to define clear, stable dependency names. If relying on default names, inspect `pytest -v --collect-only` output to find the exact node IDs.
affects: All
gotchaApplying the `@pytest.mark.dependency()` marker multiple times to the same test will result in only the *last* invocation being effective. This can silently override previously defined dependencies or custom names.
fix
Ensure each test function or class has only one `@pytest.mark.dependency()` marker. Combine all `depends` arguments into a single list if necessary.
affects: All
gotcha`pytest-dependency` manages skipping based on dependency outcomes but does not reorder tests to ensure dependencies are run first. If pytest's default collection order does not satisfy the dependencies, tests might be skipped unexpectedly because their dependencies haven't been executed yet.
fix
Consider using `pytest-order` in conjunction with `pytest-dependency` if your test suite requires explicit reordering to satisfy dependencies. Alternatively, structure your test files and classes such that dependencies naturally run before dependent tests.
affects: All
Upgrade
Version history
0.6.1latest on PyPI · released Feb 15, 2026
Audit
Dependencies
pytestrequiredCore testing framework; requires pytest 3.7.0 or newer.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
pytest-dependency — pip install pytest-dependency · libregistry