{"id":4213,"library":"pytest-find-dependencies","title":"pytest-find-dependencies","description":"A pytest plugin designed to automatically identify dependencies between tests. It achieves this by running tests in various sequences (forward and backward) and employing a binary search algorithm to pinpoint which tests rely on others. This can help uncover hidden state-based dependencies that lead to flaky tests. The current version is 0.6.0 and it is actively maintained.","status":"active","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/svenkoehler/pytest-find-dependencies","tags":["pytest-plugin","testing","dependencies","test-analysis","flaky-tests"],"install":[{"cmd":"pip install pytest-find-dependencies","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"This is a plugin for pytest, requiring pytest>=6.2.4 to function.","package":"pytest","optional":false},{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"The functionality is accessed through the pytest CLI, not direct Python imports.","symbol":"pytest-find-dependencies","correct":"This plugin is primarily activated via the pytest command-line interface using the `--find-dependencies` option. Direct Python imports into user test files for its core functionality are not typical."}],"quickstart":{"code":"import pytest\n\n# Simulate a shared state that might be modified by one test and read by another\n_shared_state = {'value': 0}\n\ndef test_setup_value():\n    \"\"\"This test sets a value in the shared state.\"\"\"\n    _shared_state['value'] = 10\n    assert True\n\ndef test_use_value():\n    \"\"\"This test depends on the value being set by test_setup_value.\"\"\"\n    assert _shared_state['value'] == 10\n\ndef test_independent():\n    \"\"\"An independent test with no dependencies.\"\"\"\n    assert 1 + 1 == 2\n\n# To run this example, save it as `test_dependencies.py` and execute:\n# pytest --find-dependencies test_dependencies.py\n# The output should indicate a dependency found between 'test_use_value' and 'test_setup_value'.","lang":"python","description":"To use `pytest-find-dependencies`, install it and then run `pytest` with the `--find-dependencies` option. The plugin will automatically analyze your tests and report any identified dependencies. The example demonstrates a logical dependency via a shared mutable state, which the plugin should detect."},"warnings":[{"fix":"Evaluate `detect-test-pollution` alongside `pytest-find-dependencies` for your use case.","message":"The plugin's author suggests considering `detect-test-pollution` as an alternative, noting its superior documentation and greater popularity.","severity":"gotcha","affected_versions":"All versions"},{"fix":"No specific user action is required; this is handled internally by the plugin to maintain correctness.","message":"When `pytest-xdist` (a plugin for parallel test execution) is detected, `pytest-find-dependencies` ensures that its internal dependency-finding test runs are not distributed. This is to prevent breaking the dependency check mechanism.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add `--fail-on-failed-tests` to your pytest command if you want failing tests to also cause a non-zero exit code.","message":"By default, the dependency analysis run returns an exit code of 1 if *any* dependency is found, even if all tests pass. If you want the exit code to reflect actual test failures, use the `--fail-on-failed-tests` option.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this limitation; some types of environment-altering dependencies might be missed depending on the initial test ordering.","message":"Dependencies that stem from a permanent change in the test environment (e.g., a resource being permanently altered) will only be found if the test causing the change runs *before* the dependent test during the plugin's analysis.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using the `--markers-to-ignore` option to exclude tests with specific ordering markers if you want them explicitly outside the dependency analysis.","message":"If you use other plugins that change test order (e.g., `pytest-order`), their ordering rules will only apply to the *first* test run during dependency analysis. Subsequent runs by `pytest-find-dependencies` for dependency isolation will define their own order.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}