A pytest plugin to find dependencies between tests
Project description
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.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-find-dependencies-0.3.0.tar.gz
.
File metadata
- Download URL: pytest-find-dependencies-0.3.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af82d751fb4125c103777d7413ae9909fa693df0b5481cd2b03d42f8a8ec1ec8 |
|
MD5 | ccb717d154c1c61bf6b94c2ee045518f |
|
BLAKE2b-256 | 03fe9e37ffcd1c514e6af602c65d21897f3aff6a8b448b6588cb496475233736 |
File details
Details for the file pytest_find_dependencies-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_find_dependencies-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c060589343d742c0e15717f729d952a8e0d097715ef6d194713368e38021a737 |
|
MD5 | d230a2d98a87ce709823ef1ed9032e12 |
|
BLAKE2b-256 | 6b6d49b6a9cbe29cd6396b5373f0b2940a76d71fb4c1eea7a2f4a2bcec1ac1ce |