pytest-find-dependencies

0.6.0 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

import pytest

# Simulate a shared state that might be modified by one test and read by another
_shared_state = {'value': 0}

def test_setup_value():
    """This test sets a value in the shared state."""
    _shared_state['value'] = 10
    assert True

def test_use_value():
    """This test depends on the value being set by test_setup_value."""
    assert _shared_state['value'] == 10

def test_independent():
    """An independent test with no dependencies."""
    assert 1 + 1 == 2

# To run this example, save it as `test_dependencies.py` and execute:
# pytest --find-dependencies test_dependencies.py
# The output should indicate a dependency found between 'test_use_value' and 'test_setup_value'.

view raw JSON →