Comments (5)
OK, I've applied this change (<<changeset e6f11f28504f (bb)>>). I suspect that cu.name is not always the right thing to use, but it certainly works better than before.
from coveragepy.
Original comment by Tomi Kallio (Bitbucket: tomikall, GitHub: tomikall)
cjulien's proposed fix for the "filename" attribute does the trick, at least Hudson's Cobertura plugin is able to find the right set of source files after applying the change. Here's a diff against the latest xmlreport.py:
diff -r [3e9229efc215 (bb)](https://bitbucket.org/ned/coveragepy/commits/3e9229efc215) coverage/xmlreport.py
--- a/coverage/xmlreport.py Wed Oct 28 08:39:31 2009 -0400
+++ b/coverage/xmlreport.py Thu Oct 29 00:51:25 2009 +0200
@@ -97,7 +97,8 @@
xclass.appendChild(xlines)
className = fname.replace('.', '_')
xclass.setAttribute("name", className)
- xclass.setAttribute("filename", os.path.split(cu.filename)[1])
+ ext = os.path.splitext(cu.filename)[1]
+ xclass.setAttribute("filename", cu.name + ext)
xclass.setAttribute("complexity", "0.0")
# For each statement, create an XML 'line' element.
What the Cobertura plugin wants is a relative path to a source file from the directory where coverage was run. In Python 2.6, the right path for the "filename" attribute can also be got from "os.path.relpath(cu.filename)".
from coveragepy.
Original comment by cjulien (Bitbucket: cjulien, GitHub: cjulien)
I test the xml output, and i was happy, my code seemed to be full covered.... but it wasn't.
In the xml I found this :
<line branch="false" hits="1" number="37"/>
<line branch="false" number="38"/>
the line 37 was effectively covered, the 38 was not... with a
<line branch="false" hits="0" number="38"/>
it will really show the uncovered lines :)
Here is my proposition for correction :
--- xmlreport_orig.py
+++ xmlreport.py
@@ -64,7 +65,8 @@
# recorded here.
if not line in missing:
l.setAttribute("hits", str(1))
-
+ else:
+ l.setAttribute("hits", str(0))
# Q: can we get info about whether this statement
# is a branch? If so, that data should be
# used here.
Another issue in the xml is the filename field :
<class branch-rate="0.0" complexity="0.0" filename="test/__init__" line-rate="1.0" name="__init__">
the filename shown here is the filename without extension....but this is not my filename, it is init.py !
I try to correct this in this way :
--- xmlreport_orig.py
+++ xmlreport.py
@@ -40,7 +40,8 @@
# Create the 'lines' and 'package' XML elements, which
# are populated later. Note that a package == a directory.
dirname, fname = os.path.split(cu.name)
+ _, ext = os.path.splitext(cu.filename)
dirname = dirname or '.'
package = packages.setdefault(
dirname, [ doc.createElement("package"), {}, 0, 0, 0, 0 ] )
@@ -48,7 +49,7 @@
c.appendChild(lines)
className = fname.replace('.', '_')
c.setAttribute("name", className)
- c.setAttribute("filename", cu.name)
+ c.setAttribute("filename", cu.name + ext)
c.setAttribute("complexity", "0.0")
try:
Hope it will be usefull :)
from coveragepy.
This feature is now checked in (as of <<changeset df70d70a32b2 (bb)>>), ready for testing.
from coveragepy.
I have every intention of merging that work back into the coverage.py trunk. I just need to find a little time...
from coveragepy.
Related Issues (20)
- Coverage fails to work on installed modules
- Cannot submit coverage since update to 7.2.4 HOT 2
- Protocol method placeholders marked as untested HOT 11
- Uncovered branches are reported if generator iterators are not exhausted HOT 6
- Cannot extract line number information from the coverage report. HOT 2
- coverage report failed to generate due to the IndexError: list index out of range HOT 2
- Allow querying the contexts in the HTML report HOT 1
- I cannot execute execute the 'def' function definition line if I call my function being measured multiple times. HOT 3
- Jinja-rendered templates appear incorrectly in log files
- can`t configure empty_line_ignoreing HOT 1
- Unable to Skip NoDataError Exception and continue with generating the report vs. Bash HOT 4
- With asynchronous exception raised, thread.is_alive() unexpectedly blocks in Python 3.11 with coverage HOT 2
- Reducing the need for multiple coverage commands (UX) HOT 1
- `coverage debug sys` can expose secrets HOT 3
- Test regressions with PyPy3.10 7.3.12rc1 HOT 4
- Cannot combine coverage files in GithubAction HOT 9
- Excluded decorators in excluded branches leak into the outer indentation.
- Mark typing.assert_never as unreachable and therefore covered. HOT 1
- coverage-7.2.7 is failing on Python 3.12.0-alpha (1 to 7) (but is working on 3.12.0-beta) HOT 7
- coverage seems to cause coroutines to skip over exeption handlers on 3.12 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coveragepy.