Different percentage in term report than the XML report

Issue #552 invalid
Eric Hanchrow created an issue

To repro this:

  • Rename "coveragerc" to ".coveragerc". (Sorry about that; I couldn't figure out how to upload it with its correct name)
  • pip install coverage==4.0.1
  • pip install pytest==2.8.2
  • pip install pytest-cov==2.2.0
  • py.test --cov-report xml --cov-report term --cov=. -v cover-me.py

You'll see cover-me.py 9 2 78% in the output, and the first line of the generated coverage.xml will say line-rate="0.7778". So far, so good.

Now change "false" to "true" in .coveragerc, and rerun it -- the .xml will remain the same, but the terminal report will say

cover-me.py 9 2 2 0 82%

I don't actually know if this is a bug, but it's surprising.

Comments (3)

  1. Ned Batchelder repo owner

    I see what's going on. The text report (and the HTML report) report a single combined number for branches and lines. The XML report keeps them separate.

    For your branch=false run:

    Name          Stmts   Miss  Cover
    cover-me.py       9      2    78%
    <coverage branch-rate="0" line-rate="0.7778"

    For the branch=true case:

    Name          Stmts   Miss Branch BrPart  Cover
    cover-me.py       9      2      2      0    82%
    <coverage branch-rate="1" line-rate="0.7778"

    Here, the "line-rate" is still 2 missed out of 9 statements, reported as 0.7778. The branch-rate is 0 missed (BrPart) out of 2, for a 100% branch rate, reported as branch-rate=1.

    So this is correct, though confusing.

  2. Log in to comment