{"id":3240,"library":"pytest-dependency","title":"pytest-dependency","description":"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.","status":"active","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/RKrahl/pytest-dependency","tags":["pytest","testing","dependency-management","plugin"],"install":[{"cmd":"pip install pytest-dependency","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core testing framework; requires pytest 3.7.0 or newer.","package":"pytest","optional":false}],"imports":[{"note":"The `dependency` marker is exposed directly via `pytest.mark`, not a separate import from `pytest_dependency` itself.","wrong":"from pytest_dependency import dependency\n@dependency()","symbol":"pytest.mark.dependency","correct":"import pytest\n@pytest.mark.dependency()"}],"quickstart":{"code":"import pytest\n\n@pytest.mark.dependency()\n@pytest.mark.xfail(reason=\"deliberate fail\", raises=AssertionError)\ndef test_a():\n    assert False\n\n@pytest.mark.dependency()\ndef test_b():\n    assert True\n\n@pytest.mark.dependency(depends=[\"test_a\"])\ndef test_c():\n    assert True\n\n@pytest.mark.dependency(depends=[\"test_b\"])\ndef test_d():\n    assert True\n\n@pytest.mark.dependency(depends=[\"test_b\", \"test_c\"])\ndef test_e():\n    assert True\n\n# To run this, save as `test_deps.py` and run `pytest -rsx test_deps.py`","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.x if you are still on Python 2.x.","message":"Version 0.6.0 (released Dec 2023) dropped support for Python 2. Ensure your test environment uses Python 3.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Upgrade `pytest` to version 3.7.0 or newer using `pip install --upgrade pytest`.","message":"Version 0.5.0 (released Feb 2020) requires `pytest` version 3.7.0 or newer. Older `pytest` versions are incompatible.","severity":"breaking","affected_versions":">=0.5.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=0.3"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"Test 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')`.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure each test function or class has only one `@pytest.mark.dependency()` marker. Combine all `depends` arguments into a single list if necessary.","message":"Applying 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}