Skip to main content

pytest-leak-finder

You have a test that passes when executed alone but fails when running its suite. What's happening? My two cents that some previous test keeps the things dirty. But wich one/s, maybe the previous are a lot, right?

This plugin helps to find a culprit by doing a binary search (alla git bisect) on the collected tests before the target.

The first time it will collect the first half of those tests plus the failing one (the target). If the target fails, we are in a good path, so, a new bisect is applied. When the target doesn't fail, it changes the "half" to bisect the next time.

Consider the following example:

$ pytest -v tests/test_demo.py 
collected 6 items                                                                                                                                            
tests/test_demo.py::test1 PASSED                                                                             
tests/test_demo.py::test2 PASSED                                                                              
tests/test_demo.py::test3 PASSED                                                                              
tests/test_demo.py::test4 PASSED                                                                             
tests/test_demo.py::test5 FAILED                                                                              
tests/test_demo.py::test6 PASSED 

$ pytest -v --lf tests/test_demo.py 
collected 6 items / 5 deselected / 1 selected                                                                                                                
tests/test_demo.py::test5 PASSED 

You can use leak finder

On the first run will set the failed test as the "target" and will stop the session.

$ pytest -v --leak-finder tests/test_demo.py 
collected 6 items

tests/test_demo.py::test1 PASSED                                                                              
tests/test_demo.py::test2 PASSED                                                                              
tests/test_demo.py::test3 PASSED                                                                              
tests/test_demo.py::test4 PASSED                                                                              
tests/test_demo.py::test5 FAILED
Leak finder: target set to tests/test_demo.py::test5

The second execution will run the first half of the tests passed before the target (let's say the half "A", composed by test1 and test2).

If the target still fail, that path is followed deeper by dividing again. But in this example it passes, so we'll discard it.

$ pytest -v --leak-finder 
collected 6 items / 3 deselected / 3 selected                                                                                                                
tests/test_demo.py::test1 PASSED                                                                              
tests/test_demo.py::test2 PASSED                                                                              
tests/test_demo.py::test5 PASSED
Leak finder: We reach the target and nothing failed. Let's change the last half.

A new execution takes the group "B", i.e. test3 and test4.

$ pytest -v --leak-finder 
collected 6 items / 3 deselected / 3 selected                                                                                                                
tests/test_demo.py::test3 PASSED                                                                              
tests/test_demo.py::test4 PASSED                                                                              
tests/test_demo.py::test5 FAILED
Leak finder: The group selected still fails. Let's do a new partition.

Lastly, a new partition is done and the group "B-A" is taken, i.e. test3

$ pytest -v --leak-finder 
collected 6 items / 3 deselected / 3 selected                                                                                                                
tests/test_demo.py::test3 PASSED                                                                              
tests/test_demo.py::test5 FAILED
Leak finder: The group selected still fails. Let's do a new partition.

And there is it, test3 is the problematic test we were looking for!

Metadata

Release files for pytest-leak-finder 0.1.0

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-leak-finder 0.1.0
File Size Uploaded
pytest-leak-finder-0.1.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-leak-finder 0.1.0
File Interpreter ABI Platform
pytest_leak_finder-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / pytest-leak-finder-0.1.0.tar.gz

Download URL pytest-leak-finder-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
36e7825258e1a5bb043587b68edff6bf5151b819e29a40d43fa64a546004f0d0
BLAKE2b-256 checksum
How to use checksums
d0bbd60f41372edfba48630b95919fc13abfe78e77fc23f93f9698daa428659c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release files / pytest_leak_finder-0.1.0-py3-none-any.whl

Download URL pytest_leak_finder-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5202fc0947696123a9b32960be916659a170aa588aea4d1747a49bf337cf272
BLAKE2b-256 checksum
How to use checksums
8f0f41dda462099b5e2fa011e6062d21718fbd69d27ecf0c70c7bae778231fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

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