coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

Coverage.py not reporting complexity metrics in cobertura.xml

Open edmondop opened this issue 2 years ago • 7 comments

For any of the files in my project, the cobertura.xml contains always a 0 for complexity.

I have hard time in understanding if the value is not computed by coverage.py (and probably we would prefer a NA then) or if my code has really such a low complexity :)

edmondop avatar Dec 30 '21 09:12 edmondop

Coverage.py doesn't measure complexity, so the XML file has no information about it.

nedbat avatar Dec 30 '21 12:12 nedbat

Maybe just updating the docs on the reporter? Why reporting zero then?

edmondop avatar Dec 30 '21 12:12 edmondop

Can you do an experiment for me? If you remove the complexity attributes from the XML file, what will your reporting tool do with it? I don't know if the file will be considered valid.

nedbat avatar Dec 30 '21 17:12 nedbat

It won't be considered valid, if you open a coverage.py generated coverage.xml the first line says

<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->

but if you open that DTD, you see that complexity is required, but is not a number, is a string. So why not N/A?

If you accept contributions, here that would be my proposal https://github.com/nedbat/coveragepy/pull/1297

edmondop avatar Dec 30 '21 17:12 edmondop

Are you using a reporting tool that reads the XML file? What does it do with "N/A"?

nedbat avatar Dec 30 '21 18:12 nedbat

You are right, although the DTD does not dictate anything around the format of that specific field, making it by contract a free form string, tools probably make assumptions that the number can be parsed.

For example, I am parsing that file via irongut/[email protected] github action which assumes it can be parsed into a double, and if cannot returns a 0.

https://github.com/irongut/CodeCoverageSummary/blob/master/src/CodeCoverageSummary/Program.cs#L170

Maybe we should file an issue to cobertura asking them to convert the DTD into XSD :) In coverage.py we can use a more explicit sentinel value, for example -1 , -99, or a negative large integer? something that obviously is not a valid complexity value

edmondop avatar Dec 30 '21 18:12 edmondop

Wouldn't you say that 0 is obviously not a valid complexity value? :)

nedbat avatar Dec 30 '21 19:12 nedbat