pytest-cov coverage.xml does not reflect multiple hits of a line

Issue #614 closed
Former user created an issue

All information with respect to pytest version 3.0.7 on a RHEL 2.6.32-504.3.3.el6.x86_64

I'm working on getting the coverage data of test files. Here's my pytest setup:

class Basic():
    def __init__(self):
        print ('Basic initialized')
    def add_num(self, num1, num2):
        counter = 0
        while (counter < 5):
            print (counter)
            counter = counter + 1
        return (num1 + num2)

class TestCalculator():
    def test_calculator(self):
        from basic import Basic
        basic_obj = Basic()
        sum_nums = basic_obj.add_num(1,2)


branch = 1

fail_under = 95
show_missing = True
precision = 2

output = coverage.xml

I'm running pytest as:

py.test --cov-report xml --cov=test/lib test/lib/

This is a snippet of the data that coverage.xml contains:

<class branch-rate="1" complexity="0" filename="test/lib/" line-rate="1" name="test/lib/basic">
        <line hits="1" number="5"/>
        <line branch="true" condition-coverage="100% (2/2)" hits="1" number="6"/>
        <line hits="1" number="7"/>
        <line hits="1" number="8"/>

In, line 6,7,8 are executed multiple times (6, 5, 5 times respectively). coverage.xml line hits does not reflect this number. Is there any development on this? Or is there any available hack that I can use?


Comments (3)

  1. Ned Batchelder repo owner

    This feature is not implemented yet, and there is no way to get the information from

  2. Ned Batchelder repo owner

    (Nikhil Hegde: I see two comments from you in my email inbox, but for some reason they don't appear on this page...)

    The trace module in the stdlib can do hit counting. can of course be extended to count as well, though it won't be a small job.

  3. Nikhil Hegde

    I see. I do know about the trace module, however, when I last executed it with certain options, it did not help with the line numbers., on the other hand, did a lot. I'll see what I can do with the trace module. Thanks, Ned :)

  4. Log in to comment