pytest-depends

1.0.1 · maintenance · verified Fri Apr 17

pytest-depends is a pytest plugin that enables defining dependencies between tests. If a test marked as a dependency fails or is skipped, any tests dependent on it will also be skipped. The current version is 1.0.1. The library is in maintenance mode with no recent updates since late 2021.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining dependent tests. `test_dependent_on_success_runs` will execute because its dependency `test_dependency_a_success` passes. `test_dependent_on_failure_is_skipped` will be marked as skipped by pytest because its dependency `test_dependency_b_failure` fails.

import pytest
import pytest_depends as depends

# This test will pass and its dependent will run
def test_dependency_a_success():
    print("\nRunning test_dependency_a_success")
    assert True

# This test will fail and its dependent will be skipped
def test_dependency_b_failure():
    print("\nRunning test_dependency_b_failure")
    assert False

@depends.depends(on=['test_dependency_a_success'])
def test_dependent_on_success_runs():
    print("\nRunning test_dependent_on_success_runs")
    assert True

@depends.depends(on=['test_dependency_b_failure'])
def test_dependent_on_failure_is_skipped():
    print("\nRunning test_dependent_on_failure_is_skipped (expected to be skipped)")
    # This assert will not be reached if the test is skipped
    assert True

# To run this example, save it as 'test_my_deps.py' and run 'pytest' from your terminal.

view raw JSON →