Skip to main content

pytest-find-dependencies

PyPI version Python versions Test suite Code coverage

A pytest plugin to find dependencies between tests.


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Summary

Tests shall generally not depend on each other. To ensure this, plugins like pytest-randomly or pytest-reverse are commonly used. These plugins find dependent tests, but it is up to you to find which test they are depend upon.

The plugin aims to automate this task. Dependencies are found in the first place by running all tests in forward and backwards direction and checking if any tests fail if executed in one order but not in the other. This will find most (but not all) test dependencies (the same way as pytest-reverse). If any dependent test is found, more test runs with a subset of all tests are run using binary search, until a test is found that causes the other test to fail.

Running tests this way may be time-consuming, especially with many tests, so it is recommended to run this only once in a while.

Installation

You can install pytest-find-dependencies via pip from PyPI:

$ pip install pytest-find-dependencies

Usage

If the plugin is installed, it can be used by adding the pytest option –find-dependencies. After running all needed tests, all found dependencies are listed. Here is an example:

=================================================
Run dependency analysis for 7 tests.
Executed 19 tests in 4 test runs.
Dependent tests:
test_one.py::test_b depends on test_one.py::test_e
=================================================

In this case 7 tests have been analyzed, one dependent test has been found after running the tests forwards and backwards, and after 2 additional test runs with an overall of 5 tests, the test it depended on was found.

Some dependencies can be due to a permanent change in the environment (for example by adding a change to a database that is not reverted in subsequent test runs). In this case, the dependency cannot be found reliably, and these tests are listed separately:

=================================================
Run dependency analysis for 5 tests.
Executed 11 tests in 3 test runs.
Tests failing permanently after all tests have run:
test_one.py::test_b
=================================================

Dependencies due to a permanent change will only be found if the offending test is run before the dependent test, otherwise the test will just fail both times.

The option --reversed-first allows you to reverse the sequence of the first two test runs.

The option --markers-to-ignore allows to define a comma-separated list of marker names. Tests that have these markers will be ignored in the analysis (e.g. not run at all). This can be used to exclude tests that have markers that define the test order. Examples include dependency (from the pytest-dependency plugin), order (from pytest-order) or depends (from pytest-depends). To ignore all tests with a dependency marker, you can use:

python -m pytest --find-dependencies --markers-to-ignore=dependency

Note that in this case you also won’t find other tests depending on the ordered markers.

Limitations

Other re-ordering plugins are only applied in the first test run, the order of the following test runs is solely defined by pytest-find-dependencies. This means that ordering tests manually will not change the outcome.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-find-dependencies” is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for pytest-find-dependencies 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-find-dependencies 0.4.0
File Size Uploaded Provenance Actions
pytest-find-dependencies-0.4.0.tar.gz 9.5 kB Without provenance Details for pytest-find-dependencies-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-find-dependencies 0.4.0
File Interpreter ABI Platform Actions
pytest_find_dependencies-0.4.0-py3-none-any.whl Python 3 none any Details for pytest_find_dependencies-0.4.0-py3-none-any.whl

Total release size: 16.5 kB

Release files / pytest-find-dependencies-0.4.0.tar.gz

Download URL pytest-find-dependencies-0.4.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cf5ecb0f76e85522424a99925e90309b4b9a344ae6c942616b208fe553986e58
BLAKE2b-256 checksum
How to use checksums
a9bd539779ed4bdcfc1622a8ac3af5c6327574f56f51af2db0c0694e31012db7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / pytest_find_dependencies-0.4.0-py3-none-any.whl

Download URL pytest_find_dependencies-0.4.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37dffcb235bce86b012f941f2480c07f4a4f4d8e08ed2cee95e687acfc28f385
BLAKE2b-256 checksum
How to use checksums
f70b9ad56ea0eac4c4deda4dfa39e9f7cda2fc91146a4d0d3e7d8aa949489d98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Security for pytest-find-dependencies 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page