eriwen / lcov-to-cobertura-xml Goto Github PK
View Code? Open in Web Editor NEWConverts lcov output to Cobertura-compatible XML for CI
Home Page: https://eriwen.github.io/lcov-to-cobertura-xml/
License: Apache License 2.0
Converts lcov output to Cobertura-compatible XML for CI
Home Page: https://eriwen.github.io/lcov-to-cobertura-xml/
License: Apache License 2.0
Works in python2.
I tried in python3 it hangs and no visible error messages. So I removed the --demangle
argument and it does not hang and it produced the xml
.
Thanks men.
When using lcov-to-cobertura-xml on a lcov file that contains coverage results for multiple source files, the line hit counts in the produced XML are the same for each source file. They match the line hit counts of the last source file mentioned in the lcov file.
Seen on Ubuntu 10.04 with Pyton 2.6.5 and Ubuntu 11.10 with Pyton 2.7.2
Hi,
I have a few problems running lcov_covertura from command line, I wrote a patch with some small changes.
diff --git a/lcov_cobertura/lcov_cobertura.py b/lcov_cobertura/lcov_cobertura.py
index f80c0a5..432cbd0 100755
--- a/lcov_cobertura/lcov_cobertura.py
+++ b/lcov_cobertura/lcov_cobertura.py
@@ -319,14 +319,14 @@ if __name__ == '__main__':
dest='output', default='coverage.xml')
(options, args) = parser.parse_args(args=argv)
- if len(argv) != 2:
- print((main.__doc__))
- sys.exit(1)
+ #if len(argv) != 2:
+ #print((main.__doc__))
+ #sys.exit(1)
try:
with open(args[1], 'r') as lcov_file:
lcov_data = lcov_file.read()
- lcov_cobertura = LcovCobertura(lcov_data, options)
+ lcov_cobertura = LcovCobertura(lcov_data, options.base_dir)
cobertura_xml = lcov_cobertura.convert()
with open(options.output, mode='wt') as output_file:
output_file.write(cobertura_xml)
I just comment the lines that checks argv len, because I don't figure out if it's a needed check. But I want to add, if it's necesary, you need to be carefoul about how the program is invoked,
./lcov_coverage
python lcov_coverage
has differents argv values.
Thanks for this amazing tool!
Could you please implement branch coverage data processing? Currently this info just is ignored.
When I use --demangle
I get:
Traceback (most recent call last):
File "/usr/local/bin/lcov_cobertura", line 9, in <module>
load_entry_point('lcov-cobertura==1.6', 'console_scripts', 'lcov_cobertura')()
File "/usr/local/lib/python3.4/dist-packages/lcov_cobertura.py", line 407, in main
cobertura_xml = lcov_cobertura.convert()
File "/usr/local/lib/python3.4/dist-packages/lcov_cobertura.py", line 86, in convert
return self.generate_cobertura_xml(coverage_data)
File "/usr/local/lib/python3.4/dist-packages/lcov_cobertura.py", line 282, in generate_cobertura_xml
'name': self.format(method_name),
File "/usr/local/lib/python3.4/dist-packages/lcov_cobertura.py", line 38, in demangle
self.pipe.stdin.write(name + "\n")
TypeError: 'str' does not support the buffer interface
I installed the latest master version via pip install git+https://github.com/eriwen/lcov-to-cobertura-xml.git
MiniDom giving memory error. Can this script lcov-to-cobertura-xml be written using xml.etree instead of minidom?
I have a .lcov file generated by llvm-cov.
/usr/lib/llvm-8/bin/llvm-cov export -format=lcov -Xdemangler c++filt -Xdemangler -n -instr-profile=xxx.profdata -object=build/bin/xxx > worker_ut.lcov
python3 /usr/local/lib/python3.9/dist-packages/lcov_cobertura/lcov_cobertura.py xxxx.lcov
When i use it in gitlab-ci:
coverage: /^\s*lines:\s*\d+.\d+\%/
artifacts:
expire_in: 1 days
reports:
cobertura: xxx.xml
junit: xxxx.xml
But it doesn't work, Test is always 0
Coming from https://gitlab.com/gitlab-org/gitlab/-/issues/328772#note_840831654
Gitlab may have issue in processing big files, so would be nice to have a parameter to split the file without using multiple tools.
Make compatible with Python 3.x using 2to3
It says in the Py file itself that the license is in the accompanied LICENSE.md file. However, I can only find a LICENSE file (without md), so this is hard to accomplish.
So should I then copy the py file to some subdir and then copy the LICENSE file to LICENSE.md into the same directory or what do you need? We'd be interested in using that file for internal processes only (test reporting, not shipping this to customers).
Also: If I copy the file as that, there is no link or anything, so how can this be traced back to you / your repo?
Best to organize project and add tests etc.
Advice here: http://infinitemonkeycorps.net/docs/pph/
Related to #23, this package needs a new release for the command line version.
According to documentation https://github.com/eriwen/lcov-to-cobertura-xml#with-pip there should be command lcov_cobertura
but there isn't.
Result is command not found.
Tested with ubuntu 14.04 with python 2.7.11
Tested with virtualenv and without.
Package versions which I tried were: 1.0, 1.1, 1.1.1, 1.2, 1.3, 1.4, 1.5, 1.6 and none of those gave me command lcov_cobertura
I've got this exception KeyError: 'hits'
In my coverage_data, some class_data['lines'][line_number] just like this:
{'branch-conditions-covered': 0, 'branch-conditions-total': 2, 'branch': 'true'}
This line could not be parsed correctly.
But this one is ok:
{'hits': '0', 'branch-conditions-covered': 0, 'branch-conditions-total': 0, 'branch': 'false'}
Hi,
With the new version 2 release I am getting the following ImportError:
File "/home/jschwender/xxx/CI/scripts/./convert_lcov_to_cobertura.py", line 5, in <module>
from lcov_cobertura import LcovCobertura
ImportError: cannot import name 'LcovCobertura' from 'lcov_cobertura' (unknown location)
I'm using python3.9. After downgrading back to version 1.6 the import works again. Any changes I should be aware of? The Readme still recommends to use from lcov_cobertura import LcovCobertura
, is this wrong now?
/tmp/./lcov_cobertura.py:21: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.spawn import find_executable
When I generate an HTML report with genhtml
I get 5623/7013 lines covered in total, which is 80%.
Looking at the xml file produced by this library the root entry has lines-covered="10233" lines-valid="23111"
, which is 44%.
How can such a situation occur?
It seems if more that one --excludes
wants to match on a single item one gets uncaught exceptions.
Changing it to an error message instead:
diff --git a/lcov_cobertura/lcov_cobertura.py b/lcov_cobertura/lcov_cobertura.py
index 379e405..3faf7a9 100755
--- a/lcov_cobertura/lcov_cobertura.py
+++ b/lcov_cobertura/lcov_cobertura.py
@@ -217,7 +217,10 @@ class LcovCobertura():
excluded = [x for x in coverage_data['packages'] for e in self.excludes
if re.match(e, x)]
for package in excluded:
- del coverage_data['packages'][package]
+ try:
+ del coverage_data['packages'][package]
+ except KeyError as ex:
+ print(f"skipping filter for {package} - not found; duplicate exclude pattern match?")
# Compute line coverage rates
for package_data in list(coverage_data['packages'].values()):
@@ -425,8 +428,8 @@ def main(argv=None):
cobertura_xml = lcov_cobertura.convert()
with open(options.output, mode='wt') as output_file:
output_file.write(cobertura_xml)
- except IOError:
- sys.stderr.write("Unable to convert %s to Cobertura XML" % args[1])
+ except IOError as ex:
+ sys.stderr.write("Unable to convert %s to Cobertura XML %s" % (args[1], ex))
if __name__ == '__main__':
Between 1.6
and 2.0
there has been a regression w.r.t. the command line entry point. Doing python -m lcov_cobertura
would work in 1.6, but produce the following error in 2.0:
../bin/python: No module named lcov_cobertura.__main__; 'lcov_cobertura' is a package and cannot be directly executed
Most probably an accidental side effect of the setup.py
-> setup.cfg
transition.
Is there a limit on the file size or if files are combined? I get segmentation fault
The file is generated by adding two files
lcov -a file1.info -a file2.info -o file.info
$ ls -lh file.info
-rw-rw-r--. 1 centos centos 23M Oct 10 17:00 file.info
$ python lcov_cobertura.py file.info
Segmentation fault
If i use a smaller file/file1 or file2 above it works
$ python lcov_cobertura.py file1.info
$ python lcov_cobertura.py file2.info
lcov: LCOV version 1.10
Running the script:
Traceback (most recent call last):
File "lcov_cobertura.py", line 359, in <module>
main(sys.argv)
File "lcov_cobertura.py", line 353, in main
cobertura_xml = lcov_cobertura.convert()
File "lcov_cobertura.py", line 55, in convert
coverage_data = self.parse()
File "lcov_cobertura.py", line 162, in parse
function_name = line_parts[-1].strip().split(',')[1]
IndexError: list index out of range
genhtml creates correct html from the coverage.info
Hi, I'm getting this error on sonarqube server:
Unknown report version: 2.0.3. This parser only handles version 1.
Not sure about this: is "report version 2.0.3" the one generated by lcov-to-cobertura converter ?
Is there any way to bump to version 1 or I have to upgrade my sonarqube server ?
Thank you in advance !
I ran lcov-to-cobertura against a lcov results file and while the conversion worked (i.e. coverage.xml was produced), I do not see function and statement summary metrics in this file. Note, I do see branch and line summary metrics:
<coverage branch-rate="0.6012965964343598" branches-covered="742" branches-valid="1234" complexity="0" line-rate="0.703875968992248" lines-covered="1362" lines-valid="1935" timestamp="1505846593" version="2.0.3">
When I generate an xml and export it to Jenkins (Cobertura plugin) I always get 100% (0/0) coverage for methods and conditionals. All other stats are non-zero as expected. Produced xml contains methods data.
What might be the problem?
In case we've subprojects generating multiple *.lcov files, it would be nice to aggregate them in a single coverage.xml
file
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.