Skip to content

Lines incorrectly reporting as not covered when running with --branch #605

Open
@nedbat

Description

@nedbat

Originally reported by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)


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:

#!python

# 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[0].has_reusable_values
    assert not strategies[0].is_empty


if __name__ == '__main__':
    test_very_deep_deferral()

When testing Hypothesis commit 8844ca758737a6439a82507e7910972c6fa22358 (bb), 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 git@github.com:HypothesisWorks/hypothesis-python.git
cd hypothesis-python
git checkout [8844ca758737a6439a82507e7910972c6fa22358 (bb)](https://bitbucket.org/ned/coveragepy/commits/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

Salient features:

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    branchbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions