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-dependencyVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to Python 3.x if you are still on Python 2.x.
Upgrade `pytest` to version 3.7.0 or newer using `pip install --upgrade pytest`.
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.
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.
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.
Ensure each test function or class has only one `@pytest.mark.dependency()` marker. Combine all `depends` arguments into a single list if necessary.
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.