branch coverage: "if" before "if False" marked as partial wrongly

Issue #598 duplicate
Daniel Hahler created an issue

The following code is considered to be 100% covered, which might be related to https://bitbucket.org/ned/coveragepy/issues/198/continue-marked-as-not-covered (i.e. line 6 should be marked as missed, but is not due to optimization?!):

for a in [True, False]:
    if a:
        print(1)

    if False:
        print(0)

However, when using branch = True, line 2 gets marked as "partial" in the html report, although line 5 should be marked as such instead.

Name         Stmts   Miss Branch BrPart  Cover   Missing
--------------------------------------------------------
t-cov-2.py       4      0      4      1    88%   2->5

Python 3.6.2 coverage.py 4.4.1

Comments (4)

  1. Ned Batchelder repo owner

    This is a duplicate of #198, in that the peephole optimizer has removed logical code paths from execution. Coverage cannot recreate the original paths.

  2. Log in to comment