Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Cobertura file sources generated #439

Closed
nedbat opened this issue Oct 27, 2015 · 15 comments
Closed

Incorrect Cobertura file sources generated #439

nedbat opened this issue Oct 27, 2015 · 15 comments
Labels
bug Something isn't working xml

Comments

@nedbat
Copy link
Owner

nedbat commented Oct 27, 2015

Originally reported by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


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
<?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>


@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


I will submit a PR on GH

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

Can you provide me with a reproducible scenario?

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


  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).

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


Another place where "relative path" is used relative to current directory and not the config.source relative to which the file was found https://github.com/nedbat/coveragepy/blob/master/coverage/python.py#L114

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

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

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


I have submitted the fix here #5
Please let me know if the nature of the fix is unclear

@nedbat
Copy link
Owner Author

nedbat commented Oct 27, 2015

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?

@nedbat
Copy link
Owner Author

nedbat commented Nov 15, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


Sample project

@nedbat
Copy link
Owner Author

nedbat commented Nov 15, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


#!bash

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>

@nedbat
Copy link
Owner Author

nedbat commented Nov 16, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


@nedbat did the provided example work for you?

@nedbat
Copy link
Owner Author

nedbat commented Nov 17, 2015

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

@nedbat
Copy link
Owner Author

nedbat commented Nov 17, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


@nedbat 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

@nedbat
Copy link
Owner Author

nedbat commented Nov 17, 2015

@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.

@nedbat
Copy link
Owner Author

nedbat commented Nov 17, 2015

Original comment by Arcadiy Ivanov (Bitbucket: arcivanov, GitHub: arcivanov)


Got it. Thanks!

@nedbat
Copy link
Owner Author

nedbat commented Nov 22, 2015

Fixed in de878ba211c4 (bb), will be 4.0.3

@nedbat nedbat closed this as completed Nov 22, 2015
@nedbat nedbat added major bug Something isn't working xml labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working xml
Projects
None yet
Development

No branches or pull requests

1 participant