From 77919cfdd11340a7965fb3c850b5cd19bb0e289a Mon Sep 17 00:00:00 2001 From: Soubhik Kumar Mitra <59209034+x612skm@users.noreply.github.com> Date: Mon, 16 Sep 2024 04:15:22 +0530 Subject: [PATCH] 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 element. Changes made: - Added the lines-covered and lines-valid attributes to the 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 --- mypy/report.py | 2 ++ test-data/unit/reports.test | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mypy/report.py b/mypy/report.py index 764cfec7799a..73942b6c5ae3 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -689,6 +689,8 @@ def on_finish(self) -> None: self.root_package.covered_lines, self.root_package.total_lines ) self.root.attrib["branch-rate"] = "0" + self.root.attrib["lines-covered"] = str(self.root_package.covered_lines) + self.root.attrib["lines-valid"] = str(self.root_package.total_lines) sources = etree.SubElement(self.root, "sources") source_element = etree.SubElement(sources, "source") source_element.text = os.getcwd() diff --git a/test-data/unit/reports.test b/test-data/unit/reports.test index 81e24240af2d..6e0fdba8aaa3 100644 --- a/test-data/unit/reports.test +++ b/test-data/unit/reports.test @@ -27,7 +27,7 @@ def bar() -> str: def untyped_function(): return 42 [outfile build/cobertura.xml] - + $PWD @@ -81,7 +81,7 @@ def foo(a: int) -> MyDict: return {"a": a} md: MyDict = MyDict(**foo(42)) [outfile build/cobertura.xml] - + $PWD