Skip to content

incorrect branch reporting with __debug__ #522

@nedbat

Description

@nedbat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions