Skip to main content

pytest plugin help to find coupled tests

Project description


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/ tests/exmaple/ tests/exmaple/
  • FAILED tests/exmaple/ tests/exmaple/ tests/exmaple/

In this case pretty simple to detect coupled tests, but if we have >=1k tests which called before it will hard



pip install pytest-sherlock

how to use:

pytest tests/exmaple/ tests/exmaple/ tests/exmaple/ --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/ PASSED                                                                                                                               [ 20%]
tests/exmaple/ PASSED                                                                                                                               [ 40%]
tests/exmaple/ PASSED                                                                                                                                    [ 60%]
tests/exmaple/ PASSED                                                                                                                                     [ 80%]
tests/exmaple/ COUPLED                                                                                                                                      [100%]
Step #2:
tests/exmaple/ PASSED                                                                                                                               [ 33%]
tests/exmaple/ PASSED                                                                                                                               [ 66%]
tests/exmaple/ COUPLED                                                                                                                                      [100%]
Step #3:
tests/exmaple/ PASSED                                                                                                                               [ 50%]
tests/exmaple/ COUPLED                                                                                                                                      [100%]

======================== found coupled in 0.08 seconds ========================
found coupled tests: 
         - tests/exmaple/
         - tests/exmaple/

pytest -l -vv tests/exmaple/ tests/exmaple/
_____________________________ 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 0x107c464b0>('b')
E        +    where <built-in method get of dict object at 0x107c464b0> = {'a': 1, 'b': 13, 'c': 3}.get

tests/exmaple/ AssertionError
======================= 7 passed, 3 coupled in 0.08 seconds ======================= 


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 =)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-sherlock, version 0.1.6
Filename, size File type Python version Upload date Hashes
Filename, size pytest_sherlock-0.1.6-py2-none-any.whl (7.8 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size pytest-sherlock-0.1.6.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page