Skip to main content

pytest-sherlock

Build Status Cov PyPI PyPI - Python Version PyPI - Wheel

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

======================= test session starts =======================
collected 10 items                                                                                                                                                                                  
Try to find coupled tests

Step #1:
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED                                                                                                                               [ 20%]
tests/exmaple/test_c_delete.py::test_delete_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 COUPLED                                                                                                                                      [100%]
Step #2:
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED                                                                                                                               [ 33%]
tests/exmaple/test_c_delete.py::test_delete_random_param PASSED                                                                                                                               [ 66%]
tests/exmaple/test_all_read.py::test_read_params COUPLED                                                                                                                                      [100%]
Step #3:
tests/exmaple/test_b_modify.py::test_modify_random_param PASSED                                                                                                                               [ 50%]
tests/exmaple/test_all_read.py::test_read_params COUPLED                                                                                                                                      [100%]

========================= COUPLED =========================
____________________ 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 0x10edb54b0>('b')
E        +    where <built-in method get of dict object at 0x10edb54b0> = {'a': 1, 'b': 13, 'c': 3}.get

tests/exmaple/test_all_read.py:8: AssertionError
================================================================================ 7 passed, 3 coupled in 0.07 seconds ================================================================================ 

TODO

I have a couple ideas, how to improve finder coupled tests:

  • use AST for detect common peace of code (variables, functions, etc...)
  • Also need to add tests for it =)

Metadata

Release files for pytest-sherlock 0.1.3

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-sherlock 0.1.3
File Size Uploaded
pytest-sherlock-0.1.3.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-sherlock 0.1.3
File Interpreter ABI Platform
pytest_sherlock-0.1.3-py2-none-any.whl Python 2 none any Details

Total release size: 12.7 kB

Release files / pytest-sherlock-0.1.3.tar.gz

Download URL pytest-sherlock-0.1.3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
190ba6b41a65bc3ec3d8a2ec1e310c4a7b9ffa132ae3c92324b0ccabe69ce838
BLAKE2b-256 checksum
How to use checksums
967df61314798d70f4eca2183ceb4405972c3e68df1de8d7a551f368d889c72c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.16

Release files / pytest_sherlock-0.1.3-py2-none-any.whl

Download URL pytest_sherlock-0.1.3-py2-none-any.whl
Size 7.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
3f9f652e1d523b2b9713e0ae31717dbea694bd6799f21a2e818e6ac2c813400d
BLAKE2b-256 checksum
How to use checksums
70046a1b0204c012cec6c6f73c88ceba0fc7884b18bc4acb75a4a62bb8198033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.16

Release history Release notifications | RSS feed

0.3.4

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

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