1. Ned Batchelder
  2. coverage.py
  3. Issues
Issue #293 resolved

Number of statement detection wrong if no newline at end of file

Marc Schlaich
created an issue

Coverage does not detect number of statements correctly in a multi line statement if it is not followed by a newline until Python 3.3. It works in Python 3.4.

$ cat cov_error.py
import subprocess
import sys

out, err = subprocess.Popen(
    [sys.executable, '-c', 'pass'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE).communicate()
$ py -2.7 -m coverage run cov_error.py && py -2.7 -m coverage report
Name        Stmts   Miss  Cover
-------------------------------
cov_error       6      0   100%

$ echo "" >> cov_error.py
$ py -2.7 -m coverage run cov_error.py && py -2.7 -m coverage report
Name        Stmts   Miss  Cover
-------------------------------
cov_error       3      0   100%

$ # revert new line in editor
$ py -3.3 -m coverage run cov_error.py && py -3.3 -m coverage report
Name        Stmts   Miss  Cover
-------------------------------
cov_error       6      0   100%

$ py -3.4 -m coverage run cov_error.py && py -3.4 -m coverage report
Name        Stmts   Miss  Cover
-------------------------------
cov_error       3      0   100%

Comments (2)

  1. Log in to comment