#๐Ÿ”’ Does coverage.py support method coverage?

34 messages ยท Page 1 of 1 (latest)

sage wyvern
#

I am using coverage.py to get line and branch coverage and it has been great. Now I heard of "Method Coverage" and I wonder if coverage.py (or py-cov) supports it. I have consulted https://coverage.readthedocs.io/, but there isn't mention to Method coverage, so maybe this is a no, but doesn't hurt to check with the experts.

The resulting XML would be as shown at https://github.com/danielpalme/ReportGenerator/blob/main/src/Testprojects/CSharp/Reports/Cobertura_coverlet.xml#L10

Maybe @dull timber knows a thing or two about this ๐Ÿ˜‰
This is a snippet of the resulting XML. note the </methods> entry.

๏ปฟ<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0.7069" branch-rate="0.75" version="1.9" timestamp="1696364443" lines-covered="152" lines-valid="215" branches-covered="9" branches-valid="12">
  <sources>
    <source>C:\temp\</source>
  </sources>
  <packages>
    <package name="Test" line-rate="0.7069" branch-rate="0.75" complexity="60">
      <classes>
        <class name="Test.AbstractClass" filename="AbstractClass.cs" line-rate="1" branch-rate="1" complexity="1">
          <methods>
            <method name=".ctor" signature="()" line-rate="1" branch-rate="1" complexity="1">
              <lines>
                <line number="7" hits="4" branch="False" />
                <line number="8" hits="4" branch="False" />
                <line number="9" hits="4" branch="False" />
                <line number="10" hits="4" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="7" hits="4" branch="False" />
            <line number="8" hits="4" branch="False" />
            <line number="9" hits="4" branch="False" />
            <line number="10" hits="4" branch="False" />
          </lines>
        </class>
      </packages>
</coverage>

Thanks

hollow valveBOT
#

@sage wyvern

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

src/Testprojects/CSharp/Reports/Cobertura_coverlet.xml line 10

<methods>```
dull timber
#

coverage.py can report on function and class coverage. If you generate an HTML report, you'll see Files, Functions, Classes at the top of the index page.

#

but the XML report doesn't expose that information

#

(function includes methods)

sage wyvern
#

Thanks for the quick reply. I noticed the <methods/> and was wondering I was doing something wrong or indeed the support was not there.

dull timber
#

in theory we could put the same info from the HTML report into the XML report. I don't know if there's a Python/Java semantic mismatch to worry about or not. Probably not.

sage wyvern
#

The main reason for my question is that I found this super cool report generator that parses the <methods> entries to highlight it on a dashboard

#

This is what drove me on this quest

#

Have you heard of a module called fun-coverage? It seems to compute the <methods>, but only reports to the terminal. it doesnt update the XML with the extra info

dull timber
sage wyvern
#

Yes, for python https://gitlab.com/redballoonsecurity/fun-coverage

The report would be something like

Name                                                                            Funcs   Miss   Cover   Missing
--------------------------------------------------------------------------------------------------------------
tests/example_test_suite/src/__init__.py                                            0      0    100%
tests/example_test_suite/src/async_function.py                                      1      0    100%
tests/example_test_suite/src/covered_function_with_partially_covered_lines.py       1      0    100%
tests/example_test_suite/src/docstring_only_function.py                             1      0    100%
tests/example_test_suite/src/excluded_function.py                                   0      0    100%
tests/example_test_suite/src/methods.py                                             2      2      0%   6, 9
tests/example_test_suite/src/non_covered_function.py                                1      1      0%   1
--------------------------------------------------------------------------------------------------------------
TOTAL                                                                               6      3     50%
dull timber
#

it's fascinating that people will write something like this (using internal functions) but not drop me a line about it.

#

Their report doesn't mention the function names? Just the number of functions?

sage wyvern
#

it seems so

dull timber
#

btw: we have a #coverage-py channel where a few others might be interested.

sage wyvern
#

oh, I didn't know, sorry. Just joined this channel after coming from coverage.py doc page.

dull timber
#

np

#

i should put a specific link to the channel in the docs.

dull timber
sage wyvern
#

That would help Discord newbies like me ๐Ÿ™‚

dull timber
#

ah, good! the channel is linked from Contributing and FAQ, but not from there. thanks.

sage wyvern
#

Would you see this feature request as something valuable for consideration?

dull timber
#

sure, the info is already in the html and json reports, so why not?

#

for all i know, there's already an issue about it.

sage wyvern
#

oh, I didnt see that. let me check the github issues again

dull timber
sage wyvern
#

lol np. i went through the issues and didnt find anything mentioning it, so I filed one issue myself

hollow valveBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.