Skip to main content

Topological sorting for pytest

Project description

Install

pip install pytest-topo

The pytest-topo library offers a topological ordering feature for pytest tests, ensuring that dependent tests are run in the correct sequence. This is particularly useful for integration testing libraries that use pytest for orchestration.

Please note that this library is not recommended for unit tests, as unit tests should ideally be independent of each other.

Usage Examples

To sequence your tests, apply the dependency and depends_on markers.

import pytest

@pytest.mark.dependency("One")
def test_one():
    # This test is executed first

@pytest.mark.depends_on("Two")
def test_three():
    # This test is executed third

@pytest.mark.depends_on("One")
@pytest.mark.dependency("Two")
def test_two():
    # This test is executed second

A test will be skipped if any of their dependencies do not pass. This will also skip any fixture creation if there are no remaining tests that need to use them.

import pytest

@pytest.mark.dependency("Fail")
def test_one():
    assert False  # force a failure

@pytest.fixture(scope="function")
def my_fixture():
    # This fixture is never created

@pytest.mark.depends_on("Fail")
def test_two(my_fixture):
    # This test will be skipped

Motivation

Consider software where customers register with an account API, and submit purchases to a purchases API. These are two services with API tests that could look like this:

tests
  - account
    - test_create_and_delete
    - ...
  - purchases
    - test_make_purchase
    - ...

The purchases tests may run a pre-test setup to create an account, execute tests, then run a post-test teardown. If there is an issue in the account creation or deletion, all these tests will error. By adding dependency links, the purchases tests will be skipped, reducing test failure noise.

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_topo-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

pytest_topo-1.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_topo-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pytest_topo-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4c92d129ef6cb819b05348aa0dca6868702cc4bdf20788b6ef4bfafb921e4831
MD5 5e44a158958ab072006531a0c3834ffb
BLAKE2b-256 1342f50f025961ef8a551d7f72a1b1206b28c3a53682ad0be81669776c48459a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_topo-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pytest_topo-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cffacc3c2e31cdb8b19cc4390da6e5a6eae0195f6047999aba89416be4a7657d
MD5 5d5ab9ba9570260f8c8951b70dc55bf8
BLAKE2b-256 7f2da2d26631c7cbf15c0951e3ff9778e349f17656f9c4616a2a54cc2b706823

See more details on using hashes here.

Supported by

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