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.
Limitations
Only dependencies are found that are reset with a new test run. If a test changes the environment permanently (for example by setting environment variables that are never reset), the dependency will not be found by this plugin.
If you have installed pytest-randomly, it will normally randomly reorder all tests. The plugin is disabled while running with –find-dependencies, and it is currently not possible to use fixed seed to start with a certain test order (may be added later).
Other re-ordering plugins are currently not taken into account, so 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
Hashes for pytest-find-dependencies-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 115a0f139ac567dca075f75cb0d51f3652f0d93e020be00db464cf694382a6a8 |
|
MD5 | ac43f72c752a579c2e32f40e34826632 |
|
BLAKE2b-256 | e0ef1db29b5d0d626ecbddfa7dd2f47b580799d474c8af261b4c6f89b75f7dff |
Hashes for pytest_find_dependencies-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 780492b46271958996bca7374441118b26d57016935d99b066b363991263f62b |
|
MD5 | f40c7e64ba1d8d66fc63bf7184904e79 |
|
BLAKE2b-256 | e92c35d71fb8cfefc8544f1d9650318726203857f295adde0f2510d8792c0d84 |