Registry / testing / lcov-cobertura

lcov-cobertura

JSON →
library2.1.1pypypi✓ verified 22d ago

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.

pip install lcov_cobertura
INSTALL
IMPORT
SIG · LCOV-COBERTURA
L
lcov-cobertura
testingpythonv2.1.1
Install
1.6s avg
Import
169ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.182s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.156s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LcovCobertura
from lcov_cobertura import LcovCobertura

Demonstrates how to use LcovCobertura as a Python module to convert LCOV data to Cobertura XML. The `base_dir` parameter is important for correctly resolving source file paths within the Cobertura report.

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)
lcov-cobertura --version
Debug
Known issues
breakingPython 2.x support was dropped after version 1.6. Versions 2.0.0 and above explicitly require Python 3.8+.
fix
Upgrade your Python environment to 3.8 or newer, or use lcov-cobertura version 1.6 or older (not recommended due to lack of maintenance).
affects: >=2.0.0
gotchaWhen 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.
fix
Ensure `c++filt` (part of GNU Binutils) is installed and accessible in the system's PATH if C++ demangling is required.
affects: All versions
gotchaIncorrectly 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.
fix
Always verify that `base_dir` points to the root directory where your source files are located relative to the paths in your LCOV report.
affects: All versions
Errors
Common errors & fixes
Python versions 2.0.0 and above explicitly require Python 3.8+
The installed Python version is older than 3.8, while lcov-cobertura versions 2.0.0 and newer require Python 3.8 or later.
fix
Upgrade your Python environment to version 3.8 or newer. If upgrading Python is not feasible, use an older version of lcov-cobertura (e.g., 1.6 or older), though this is not recommended due to lack of maintenance.
ModuleNotFoundError: No module named 'distutils'
The `distutils` module, which lcov-cobertura might be trying to import, has been deprecated or removed in newer Python versions (e.g., Python 3.12+).
fix
Ensure your Python environment is set up correctly, and if you are on a very recent Python version, consider if there's an update to lcov-cobertura that removes this dependency or if a compatibility layer is needed. For NixOS users, this might require adding `setuptools` as a dependency.
lcov_cobertura: command not found
The `lcov_cobertura` executable is either not correctly installed, not in your system's PATH, or you are using an older version (pre-1.6) that did not properly install the command-line entry point.
fix
Ensure `lcov-cobertura` is installed via `pip install lcov_cobertura`. If already installed, verify that your system's PATH includes the directory where pip installs executables. For older versions, directly running the Python script might be necessary: `python -m lcov_cobertura lcov-file.dat`.
c++filt utility must be available in your system's PATH
When using the `--demangle` command-line option or the `demangle=True` parameter in the `LcovCobertura` constructor for C++ function name demangling, the `c++filt` utility (part of GNU Binutils) is required but not found in the system's PATH.
fix
Install GNU Binutils (which includes `c++filt`) and ensure its location is accessible in your system's PATH environment variable.
Incorrect source file paths in Cobertura XML report (often preventing CI tools from linking coverage data)
The `--base-dir` command-line option or `base_dir` parameter in the Python API is incorrectly set, causing the Cobertura XML report to reference source files with paths that do not match their actual location relative to the CI environment or project root.
fix
Always verify that the `--base-dir` (or `base_dir`) parameter points to the root directory where your source files are located, relative to the paths reported in your LCOV file. The default is the current working directory.
Upgrade
Version history
2.1.1latest on PyPI · released Feb 22, 2025
Audit
Dependencies
c++filtoptionalRequired for demangling C++ function names when the '--demangle' option is used.
Agent activity
1 hits · last 30 days
Resources
lcov-cobertura — pip install lcov-cobertura · libregistry