Strange "-1" line number in branch coverage output

Issue #469 resolved
Ionel Cristian Mărieș
created an issue

This test is a bit strange but humour this scenario:

driver.py

import sys
import os
try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

import coverage

master_cov = coverage.coverage(branch=True, data_suffix=True)
master_cov.erase()

slave_cov = coverage.coverage(branch=True, data_suffix=True)
slave_cov.start()
import foo
slave_cov.stop()
slave_cov.save()

buff = StringIO()
slave_cov.data.write_fileobj(buff)
print(buff.getvalue())
master_cov.start()
master_cov.data.read_fileobj(StringIO(buff.getvalue()))
master_cov.stop()
master_cov.save()

master_cov.report(show_missing=True)    

foo.py

import sys

idx = 0

if idx == 0:
    pass

Run python driver.py and we get:

!coverage.py: This is a private format, don't read it directly!{"arcs": {"/home/ionel/sandbox/foo.py": [[5, 6], [6, -1], [-1, 1], [1, 3], [3, 5]]}}
Name     Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------
foo.py       4      0      2      1    83%   5->-1

The -1 is rather strange.

Comments (9)

  1. Ned Batchelder repo owner

    Hmm, interesting! have I forgotten about negative numbers in the text report? This reproduces with just, "coverage run --branch foo.py; coverage report -m" also. No need for driver.py at all.

  2. Ned Batchelder repo owner

    -1 means, a branch to the exit of the code object starting at line 1. In this case, there is no branch from line 5 out of the module (it's a missing "else" essentially). In the HTML report, negative numbers are shown as "exit".

  3. Log in to comment