Coverage gets confused when encoding comment is in the wrong place · Issue #443 · nedbat/coveragepy (original) (raw)
Originally reported by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)
It seems that code which incorrectly has things before the encoding comment confuses coverage.
Reproduction:
conventions.py:
from future import division, print_function, absolute_import
coding=utf-8
class UniqueIdentifier(object):
def __init__(self):
pass
not_set = UniqueIdentifier()
test_conventions.py:
Then running the following:
python -m coverage run test_conventions.py && coverage report --show-missing
Causes coverage to report that the file conventions.py has not got 100% coverage (it does), but also gives nonsensical line numbers:
Name Stmts Miss Cover Missing
---------------------------------------------------
conventions.py 5 3 40% 4, 7-10
test_conventions.py 1 0 100%
---------------------------------------------------
TOTAL 6 3 50%
Line 4 is the encoding comment, and lines 7-10 correspond to the class body.
I have tested this on Python 3.4.3 running coverage 4.0.2. I noticed this when my CI started breaking (I erroneously had some code like this due to a confused formatter) on a coverage upgrade, so I think it's probably introduced in a recent version.