Report incorrect with branch coverage

memedough avatarmemedough created an issue

using coverage 3.5.1

coverage run test_foo.py

contents is (it won't do anything but define functions, just example file at hand)

import sys

def pytest_generate_tests(metafunc):
    for i in range(10):
        metafunc.addcall()

def test_foo():
    version = sys.version_info[:2]
    if version == (2, 4):
        a = True
    if version == (2, 5):
        a = True
    if version == (2, 6):
        a = True
    if version == (2, 7):
        a = True
    if version == (3, 0):
        a = True
    if version == (3, 1):
        a = True
    if version == (3, 2):
        a = True

do report on .coverage data

coverage report

give

Name       Stmts   Miss Branch BrPart  Cover
--------------------------------------------
test_foo      20     17     16      0    53%

why 53% when only 3 lines covered?

do with branch off get

Name       Stmts   Miss  Cover
------------------------------
test_foo      20     17    15%

is better 15%

Comments (6)

  1. Kevin Qiu

    Running the test file against TIP

     [kevin@antares] (py: env) ~/src/coverage.py
    [default:2c5fb3a8b81c] $ coverage --version
    Coverage.py, version 3.6.1a0.  http://nedbatchelder.com/code/coverage/3.6.1a0
    
     [kevin@antares] (py: env) ~/src/coverage.py
    [default:2c5fb3a8b81c] $ coverage run test_foo.py 
    
     [kevin@antares] (py: env) ~/src/coverage.py
    [default:2c5fb3a8b81c] $ coverage report
    Name       Stmts   Miss  Cover
    ------------------------------
    test_foo      20     17    15%
    
  2. Ned Batchelder

    Kevin, I'm not sure what you've just posted here? It looks like you are confirming that the original report is still accurate? The OP had a final line that looks just like yours.

  3. Kevin Qiu

    Here's the output when I have --branch option on.

    $ coverage report
    Name       Stmts   Miss Branch BrMiss  Cover
    --------------------------------------------
    test_foo      20     17     16     16     8%
    

    which is correct given the definition of coverage (num of executed lines + num of executed branches) / (total lines + total branches)

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.