LCOV to Cobertura XML Converter
lcov-cobertura is a Python library that converts code coverage reports from the LCOV format to the Cobertura XML format. This conversion is crucial for integration with Continuous Integration (CI) servers like Jenkins, which often use Cobertura XML to aggregate results and assess build stability. The library is actively maintained, with the current version 2.1.1 released in February 2025, and supports Python 3.8 and newer versions.
Warnings
- breaking Python 2.x support was dropped after version 1.6. Versions 2.0.0 and above explicitly require Python 3.8+.
- gotcha When using the '--demangle' command-line option or the `demangle=True` parameter in the `LcovCobertura` constructor, the `c++filt` utility must be available in your system's PATH. Without it, C++ function name demangling will fail silently or with an error.
- gotcha Incorrectly setting the `--base-dir` (command-line) or `base_dir` (Python API) can lead to Cobertura XML reports with incorrect source file paths, preventing CI tools from linking coverage data to source files. The default is the current working directory.
Install
-
pip install lcov_cobertura
Imports
- LcovCobertura
from lcov_cobertura import LcovCobertura
Quickstart
from lcov_cobertura import LcovCobertura # Example LCOV input data lcov_input = """ SF:/path/to/source/file.py DA:1,1 DA:2,0 end_of_record SF:/path/to/another/file.py DA:5,1 DA:6,1 end_of_record """ converter = LcovCobertura(lcov_input, base_dir='.') cobertura_xml = converter.convert() print(cobertura_xml)