Skip to main content

A Python package for managing test dependencies in pytest.

Project description

PyPI version Python Development Status Maintenance PyPI License


pytest-depends-on

An advanced pytest plugin designed for Python projects, offering robust dependency management utilities to enhance the testing workflow.
It allows tests to be skipped based on the execution status of other tests, ensuring that dependent tests do not run if their prerequisites fail or are skipped, resulting in a cleaner and more efficient testing experience.


🚀 Features

  • depends-on: A powerful marker to declare test dependencies. If a parent test fails or hasn't run, the dependent test is automatically skipped.
    • Marker: @pytest.mark.depends_on
    • Arguments:
      • tests (list): A list of parent test names (node IDs) that the current test depends on.
      • status (optional): The expected status of the parent test. Defaults to PASSED. The dependent test will skip if the parent status does not match this value.
      • allowed_not_run (optional): Boolean. If True, the test will not skip if the parent test has not run yet. Defaults to False (skips if parent is missing).

    • Automatic Status Tracking: Automatically tracks the result (passed, failed, skipped, xfailed, xpassed) of every test during the call phase to resolve dependencies dynamically.

📦 Installation

pip install pytest-depends-on

🔧 Usage

1. Register the marker

Add the marker to your pytest.ini file to avoid warnings (optional, as the plugin programmatically registers it, but good practice):

[pytest]
markers =
    depends_on: mark test as dependent on another test

2. Implement in your tests

Use the marker decorator on your test functions.

Basic Dependency: test_child will only run if test_parent passes.

import pytest

def test_parent():
    assert True

@pytest.mark.depends_on(tests=["test_parent"])
def test_child():
    assert True

Custom Status Dependency: test_child will run only if test_parent fails (useful for testing error handling or recovery).

import pytest

from pytest_depends_on.consts.status import Status

@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
def test_child():
    pass

Soft Dependency: test_child will run even if test_parent hasn't executed yet (e.g., due to ordering).

import pytest

@pytest.mark.depends_on(tests=["test_parent"], allowed_not_run=True)
def test_child():
    pass

🤝 Contributing

If you have a helpful tool, pattern, or improvement to suggest: Fork the repo
Create a new branch
Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.


🙏 Thanks

Thanks for exploring this repository!
Happy coding!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_depends_on-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_depends_on-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_depends_on-1.0.1.tar.gz.

File metadata

  • Download URL: pytest_depends_on-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_depends_on-1.0.1.tar.gz
Algorithm Hash digest
SHA256 653ca0709e658b0a46c6f0f31b2a8635892ba3692bd95c5b28057962100a5962
MD5 60d09a247433df93eb99d74d92ebf54d
BLAKE2b-256 9844662a41a1074e746e2986153e1a7145abd929733eda61be905aae0ad73d01

See more details on using hashes here.

File details

Details for the file pytest_depends_on-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_depends_on-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae8e3c87f85ed0966501552741d815c304418cdaabd04c7ee3a29c55f16ee9a2
MD5 b8d8208862f4a4e6b5c26e192f59591b
BLAKE2b-256 064f7a8a65bade61a4ebc0393a5ed17a6dbe1b8ebfeb7ce2f6333b502dfef80e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page