Skip to content

Commit 77919cf

Browse files
authored
Add missing lines-covered and lines-valid attributes (#17738)
This PR resolves an issue where the Cobertura XML report generated by MyPy was missing the lines-covered and lines-valid attributes in the <coverage> element. Changes made: - Added the lines-covered and lines-valid attributes to the <coverage> element in the Cobertura XML report. - Updated the CoberturaReportSuite test suite to validate that these attributes are correctly included in the generated XML. Fixes #17689
1 parent 8b1e606 commit 77919cf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

mypy/report.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ def on_finish(self) -> None:
689689
self.root_package.covered_lines, self.root_package.total_lines
690690
)
691691
self.root.attrib["branch-rate"] = "0"
692+
self.root.attrib["lines-covered"] = str(self.root_package.covered_lines)
693+
self.root.attrib["lines-valid"] = str(self.root_package.total_lines)
692694
sources = etree.SubElement(self.root, "sources")
693695
source_element = etree.SubElement(sources, "source")
694696
source_element.text = os.getcwd()

test-data/unit/reports.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def bar() -> str:
2727
def untyped_function():
2828
return 42
2929
[outfile build/cobertura.xml]
30-
<coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="0.7500" branch-rate="0">
30+
<coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="0.7500" branch-rate="0" lines-covered="6" lines-valid="8">
3131
<sources>
3232
<source>$PWD</source>
3333
</sources>
@@ -81,7 +81,7 @@ def foo(a: int) -> MyDict:
8181
return {"a": a}
8282
md: MyDict = MyDict(**foo(42))
8383
[outfile build/cobertura.xml]
84-
<coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="1.0000" branch-rate="0">
84+
<coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="1.0000" branch-rate="0" lines-covered="6" lines-valid="6">
8585
<sources>
8686
<source>$PWD</source>
8787
</sources>

0 commit comments

Comments
 (0)