incorrect branch reporting with debug · Issue #522 · nedbat/coveragepy (original) (raw)

Originally reported by John Theodore Goetz (Bitbucket: theodoregoetz, GitHub: theodoregoetz)


Coverage report indicates a missing branch with __debug__ within an if/else block. Note if a pass is added after the if __debug__ then coverage is correctly shown as 100%.

#!python

for value in [True, False]:
    if value:
        if __debug__:
            x = 1
        #pass  # required for coverage to show 100%
    else:
        x = 2

Running coverage in both __debug__ and with python -O (appending the results):

#!bash

python -mcoverage erase
python -mcoverage run --branch prog.py
python -O -mcoverage run --branch --append prog.py
python -mcoverage report -m

Results in the following:

#!bash

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