I ran into this problem when testing Hypothesis: Lines that are definitely covered by a test are showing up as uncovered in coverage.
The following is the test file:
# coding=utf-8 from __future__ import division, print_function, absolute_import import hypothesis.strategies as st def test_very_deep_deferral(): def strat(i): if i == 0: return st.deferred(lambda: st.one_of(strategies + [st.none()])) else: return st.deferred( lambda: st.tuples(strategies[(i + 1) % len(strategies)])) strategies = list(map(strat, range(100))) assert strategies.has_reusable_values assert not strategies.is_empty if __name__ == '__main__': test_very_deep_deferral()
When testing Hypothesis commit 8844ca758737a6439a82507e7910972c6fa22358, this shows lines 156-158 in src/hypothesis/searchstrategy/strategies.py as uncovered. However the lines are definitely covered by this test (see below for evidence).
To reproduce this problem:
git clone email@example.com:HypothesisWorks/hypothesis-python.git cd hypothesis-python git checkout 8844ca758737a6439a82507e7910972c6fa22358
(now copy the above example as test_local.py)
PYTHONPATH=src python -m coverage run --branch --rcfile=/dev/null --include=src/hypothesis/searchstrategy/strategies.py test_local.py coverage report --rcfile=/dev/null --show-missing
- The lines 156-158 show up in the report.
- If you rerun it without "--branch" in the "coverage run" line they do not.
- If you add "assert False" at line 156, the test fails. Thus the coverage run without "--branch" is correct.