coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

'pass' causes pragma no cover to be ignored

Open nedbat opened this issue 8 years ago • 2 comments

Originally reported by John Vandenberg (Bitbucket: jayvdb, GitHub: jayvdb)


If a branch only contains pass it is required to be covered even if the branch is #pragma: no cover.

For example, in the following

foo = True

if foo == True:
    foo = False
else:  # pragma: no cover
    pass

if foo == False:
    foo = True
else:  # pragma: no cover
    None

Only the first else requires coverage; using None instead of pass rectifies the problem.

$ coverage report --show-missing
Name               Stmts   Miss Branch BrPart  Cover   Missing
--------------------------------------------------------------
coverage_demo.py       5      0      2      1    86%   3->8

  • Bitbucket: https://bitbucket.org/ned/coveragepy/issue/576

nedbat avatar May 03 '17 12:05 nedbat

@nedbat potential issue for sprint?

jonkiparsky avatar Mar 13 '23 20:03 jonkiparsky

This feels like something that behaves differently on different versions of Python. We should investigate.

nedbat avatar Mar 15 '23 13:03 nedbat