LCOV to Cobertura XML Converter

2.1.1 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

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)

view raw JSON →