hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Letting coverage report generate XML

Open ydirson opened this issue 3 months ago • 4 comments

For integration with Gitlab (so it can show coverage info in a PR) we need to get the XML coverage output. The only solution currently seems to use custom scripts, duplicating most of the builtin configuration, which looks very suboptimal. Discussion on this topic was launched without much success.

What would the best solution look like to integrate this?

  • Have a --cover-xml toggle run a new cov-xml script? AFAICT that would break all configurations that do use custom scripts, until they add a custom cov-xml (unless the custom-scripts system is first changed to avoid having to repeat entries we don't need to change, but one way or the other user expectations will be broken)
  • Just being able to override a single script with cov-combine = ["coverage combine", "coverage xml"] would already be a massive improvement
  • Other ideas?

ydirson avatar Aug 29 '25 22:08 ydirson

Just being able to override a single script

for sure, that’s the biggest issue here.

it’s easy to run custom commands in the test environment, but it’s hard to make small modifications to the default scripts.

flying-sheep avatar Sep 02 '25 08:09 flying-sheep

If something similar to #1477 is merged, to generate an XML report could involve adding the following to hatch.toml

[envs.hatch-test]
reporting = "xml"

jborbely avatar Sep 16 '25 05:09 jborbely

This should already be possible with hatch, coverage has its own header for configuration in pyproject.toml so you can have

[tool.coverage.xml]
output = mydir/foo/bar.xml

which will then output xml to the specified output location and does not require changing anything with the hatch default scripts at all. See https://coverage.readthedocs.io/en/7.10.7/config.html#sample-file

cjames23 avatar Sep 27 '25 23:09 cjames23

No, that just configures how coverage xml behaves. You still have to call it.

flying-sheep avatar Sep 28 '25 12:09 flying-sheep