pytest-sherlock
Pytest plugin which help to find coupled tests.
Sometimes we have coupled tests which depend from ordering
For example:
- PASSES
tests/exmaple/test_all_read.py tests/exmaple/test_b_modify.py tests/exmaple/test_c_delete.py - FAILED
tests/exmaple/test_c_delete.py tests/exmaple/test_b_modify.py tests/exmaple/test_all_read.py
In this case pretty simple to detect coupled tests, but if we have >=1k tests which called before it will hard
Content:
Install
pip install pytest-sherlock
how to use:
pytest tests/exmaple/test_c_delete.py tests/exmaple/test_b_modify.py tests/exmaple/test_all_read.py --flaky-test="test_read_params" -vv
Plugin didn't run all tests, it try to find some possible guilty test and will run first
Try to find coupled tests in [3-4] steps
__________________________ Step [1 of 4]: __________________________
tests/exmaple/test_c_delete.py::test_delete_random_param PASSED [ 20%]
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED [ 40%]
tests/exmaple/test_c_delete.py::test_deleted_passed PASSED [ 60%]
tests/exmaple/test_c_delete.py::test_do_not_delete PASSED [ 80%]
tests/exmaple/test_all_read.py::test_read_params FAILED [100%]
__________________________ Step [2 of 4]: __________________________
tests/exmaple/test_c_delete.py::test_delete_random_param PASSED [ 33%]
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED [ 66%]
tests/exmaple/test_all_read.py::test_read_params FAILED [100%]
__________________________ Step [3 of 4]: __________________________
tests/exmaple/test_c_delete.py::test_delete_random_param PASSED [ 50%]
tests/exmaple/test_all_read.py::test_read_params PASSED [100%]
__________________________ Step [4 of 4]: __________________________
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED [ 50%]
tests/exmaple/test_all_read.py::test_read_params FAILED [100%]
============================== FAILURES ==============================
__________________________ test_read_params __________________________
Found coupled tests:
tests/exmaple/test_b_modify.py::test_modify_random_param
tests/exmaple/test_all_read.py::test_read_params
Common fixtures:
config
How to reproduce:
pytest -l -vv tests/exmaple/test_b_modify.py::test_modify_random_param tests/exmaple/test_all_read.py::test_read_params
AssertionError: assert 13 == 2
+ where 13 = <built-in method get of dict object at 0x102664280>('b')
+ where <built-in method get of dict object at 0x102664280> = {'a': 1, 'b': 13, 'c': 3}.get
tests/exmaple/test_all_read.py:8: AssertionError
=================== 1 failed, 9 passed in 0.08 seconds ===================
The plugin also supports --lf (last failed) option to rerun found coupled tests.
It allows us to make sure that coupled tests are true.
pytest tests/exmaple/test_c_delete.py tests/exmaple/test_b_modify.py tests/exmaple/test_all_read.py --lf
=========================================================================== test session starts ============================================================================
platform darwin -- Python 3.7.10, pytest-3.5.1, py-1.7.0, pluggy-0.6.0
collected 10 items / 8 deselected
run-last-failure: rerun previous 2 failures
tests/exmaple/test_b_modify.py . [ 50%]
tests/exmaple/test_all_read.py F [100%]
================================================================================= FAILURES =================================================================================
_____________________________________________________________________________ test_read_params _____________________________________________________________________________
config = {'a': 1, 'b': 13, 'c': 3}, param = 'b'
def test_read_params(config, param):
> assert config.get(param) == 2
E AssertionError: assert 13 == 2
E + where 13 = <built-in method get of dict object at 0x10c964cd0>('b')
E + where <built-in method get of dict object at 0x10c964cd0> = {'a': 1, 'b': 13, 'c': 3}.get
tests/exmaple/test_all_read.py:6: AssertionError
============================================================= 1 failed, 1 passed, 8 deselected in 0.05 seconds =============================================================
TODO
I have a couple ideas, how to improve finder coupled tests:
- use AST for detect common peace of code (variables, functions, etc...)
Metadata
Release files for pytest-sherlock 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-sherlock-0.3.4.tar.gz | 18.4 kB | Without provenance | Details for pytest-sherlock-0.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_sherlock-0.3.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pytest_sherlock-0.3.4-py2.py3-none-any.whl |
Total release size: 29.7 kB
Release files / pytest-sherlock-0.3.4.tar.gz
| Download URL | pytest-sherlock-0.3.4.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82e5958ac459f69858e8b268e7e1a9078498b8ab3d5f6a0a29e6a9cba42d5f8a
|
|
BLAKE2b-256 checksum How to use checksums |
ff67acf66aa57e8fcc8ce1f6398e92a4d34ce8752561f87f1f33042b3f020442
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / pytest_sherlock-0.3.4-py2.py3-none-any.whl
| Download URL | pytest_sherlock-0.3.4-py2.py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
be70850cd7504e343f17537a892cbe0ce7dff95db440331a25188370da98ab30
|
|
BLAKE2b-256 checksum How to use checksums |
f7a55ba64c646ca1cace7a0797e3a847a76d9154b4056305f5b52d7bab06bdec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for pytest-sherlock 0.3.4
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.