a tool to detect test pollution
Low maintenance activity. Last release over 3 years ago, commits in 6 of the last 26 weeks. Weaker on recent releases and release cadence.
pip install detect-test-pollutiondetect-test-pollution
a tool to detect test pollution
installation
pip install detect-test-pollution
what is test pollution?
test pollution is where a test fails due to the side-effects of some other test in the test suite.
it usually appears as a "test flake" something where the test fails mysteriously but passes when run by itself.
a simple example of this is the following python code:
k = 1
def test_k():
assert k == 1
def test_k2():
global k
k = 2
assert k == 2
now this example is a little bit silly, you probably wouldn't write code this poorly but helps us demonstrate the problem here.
when run normally -- these tests pass:
$ pytest -q t.py
.. [100%]
2 passed in 0.00s
but, if the tests were run in some other order (due to something like pytest-randomly or pytest-xdist) then the pollution would be apparent:
$ pytest -q t.py::test_k2 t.py::test_k
.F [100%]
=================================== FAILURES ===================================
____________________________________ test_k ____________________________________
def test_k():
> assert k == 1
E assert 2 == 1
t.py:4: AssertionError
=========================== short test summary info ============================
FAILED t.py::test_k - assert 2 == 1
1 failed, 1 passed in 0.03s
often this flake happens in a codebase with hundreds or thousands of tests and it's difficult to track down which test is causing the global side-effects.
