Incorrect Cobertura file sources generated

Issue #439 resolved
Arcadiy Ivanov created an issue

Consider the following snippet.

Observe <source>/Users/arcivanov/Documents/src/cschcs/cschcs-manager

Observe filename="another_api/models.py" line-rate="1" name="models.py"

The problem is, this is pyb and the sources are actually located in src/main/python.

Unfortunately, coverage simply uses current directory for sources for unknown reason (https://github.com/nedbat/coveragepy/blob/master/coverage/xmlreport.py#L146) -files.relative_directory() is always current dir and disregards Coverage(source=['src/main/python'])

The expected result would, naturally, be <source>/Users/arcivanov/Documents/src/cschcs/cschcs-manager/src/main/python

<?xml version="1.0" ?>
<coverage branch-rate="0.9348" line-rate="1" timestamp="1445905926898" version="4.0.1">
        <!-- Generated by coverage.py: https://coverage.readthedocs.org -->
        <!-- Based on https://raw.githubusercontent.com/cobertura/web/f0366e5e2cf18f111cbd61fc34ef720a6584ba02/htdocs/xml/coverage-03.dtd -->
        <sources>
                <source>/Users/arcivanov/Documents/src/cschcs/cschcs-manager</source>
        </sources>
        <packages>
                <package branch-rate="1" complexity="0" line-rate="1" name=".">
                        <classes>
                                <class branch-rate="1" complexity="0" filename="another_api.py" line-rate="1" name="another_api.py">
                                        <methods/>
                                        <lines>
                                                <line hits="1" number="8"/>
                                        </lines>
                                </class>
                                <class branch-rate="1" complexity="0" filename="hcsos.py" line-rate="1" name="hcsos.py">
                                        <methods/>
                                        <lines>
                                                <line hits="1" number="8"/>
                                        </lines>
                                </class>
                        </classes>
                </package>
                <package branch-rate="1" complexity="0" line-rate="1" name="another_api">
                        <classes>
                                <class branch-rate="1" complexity="0" filename="another_api/models.py" line-rate="1" name="models.py">
                                        <methods/>
                                        <lines>
                                                <line hits="1" number="10"/>
                                                <line hits="1" number="13"/>
                                                <line hits="1" number="15"/>
                                                <line hits="1" number="16"/>
                                                <line hits="1" number="17"/>
                                                <line hits="1" number="19"/>
                                                <line hits="1" number="20"/>
                                                <line hits="1" number="21"/>
                                                <line hits="1" number="22"/>
                                        </lines>
                                </class>
                                <class branch-rate="1" complexity="0" filename="another_api/resources.py" line-rate="1" name="resources.py">
                                        <methods/>
                                        <lines>
                                                <line hits="1" number="8"/>
                                                <line hits="1" number="9"/>
                                                <line hits="1" number="11"/>
                                                <line hits="1" number="14"/>
                                                <line hits="1" number="15"/>
                                                <line hits="1" number="16"/>
                                                <line hits="1" number="19"/>
                                                <line hits="1" number="20"/>
                                                <line hits="1" number="22"/>
                                        </lines>
                                </class>
                        </classes>
                </package>

Comments (18)

  1. Arcadiy Ivanov reporter
    1. Create a Python Builder project (pybuilder > v0.11.0)
    2. Have some source files and unit tests
    3. Run a build.
    4. Inspect target/reports/unittest_coverage.xml

    Let me see if there are any public projects available you can look at (all mine are private).

  2. Ned Batchelder repo owner

    @arcivanov Hmm, I'm afraid I need a considerably greater level of detail in the instructions in order to duplicate your issue.

  3. Ned Batchelder repo owner

    If you could use Python Builder to make a small project, and attach a zip file here, it'll be easier for me to assess the problem and the solution. Or perhaps if the pull request had some tests?

  4. Arcadiy Ivanov reporter
    pip install --pre pybuilder
    tar -xf issue_439.tar.gz
    cd issue_439
    pyb
    less target/reports/coverage.xml
    

    Observe <source>issue_439 and not issue_430/src/python</source>

  5. Ned Batchelder repo owner

    Yes, thanks, this reproduces the behavior. I need to understand what's happening at the API level now.

  6. Arcadiy Ivanov reporter

    @ned see the PR I sent: the code change is tiny and demonstrates the problem - the sources are assumed to be in "." always for whatever reason

  7. Ned Batchelder repo owner

    @arcivanov just to be clear: your PR doesn't demonstrate the problem, it contains a fix. I want to see and understand the problem for myself. This is on my list, I will get to it soon.

  8. Log in to comment