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:

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

import coverage

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

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

buff = StringIO()

import sys

idx = 0

if idx == 0:

Run python and we get:

! This is a private format, don't read it directly!{"arcs": {"/home/ionel/sandbox/": [[5, 6], [6, -1], [-1, 1], [1, 3], [3, 5]]}}
Name     Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------       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; coverage report -m" also. No need for 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. Ionel Cristian Mărieș reporter

    Instead of 123->-1 you could have 123->$ - or I'm misunderstanding the question? Why is it important?

  4. Log in to comment