Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I combine mypy reports with pytest coverage reports?

I can generate a type "coverage" report with mypy via

mypy . --html-report mypy-report

and a pytest coverage report with pytest-cov

pytest --cov=app --cov-report=html

Is there a way to combine both reports? I would be interested in code that is neither covered by unit tests nor by mypy.

like image 380
Martin Thoma Avatar asked Oct 15 '20 11:10

Martin Thoma


1 Answers

I spent a little time on this, and made some progress, but don't have a fully working solution.

Both pytest and mypy have flags to emit an XML-based report, and the one common schema they share is for the Java-based Cobertura tool.

Example invocation to produce an XML file for each:

pytest --cov=app --cov-report=xml:pytest-cobertura.xml
mypy app.py --cobertura-xml-report .

After this, you'll have two similar XML files named:

  • pytest-cobertura.xml
  • coverage.xml - mypy will only allow a directory, not a filename

I've explored trying to merge these two files into a single one, but haven't been able to successfully do so in the time I've spent on this - but it should be something along the lines of parsing the XML tree and merging the two sets of lines XML tags and creating a combined.xml file.

Right now, each file individually can be rendered to either terminal or HTML with the pycobertura tool, like so:

pycobertura show --format html --output coverage.html combined.xml

I haven't been able to figure out the merging just yet, but wanted to give you what I had figured out.

like image 199
Mike Fiedler Avatar answered Oct 14 '22 03:10

Mike Fiedler