pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

Add JSON format to --cov-report

Open pedrorrivero opened this issue 4 years ago • 7 comments

Before proposing please consider:

  • the maintenance cost of the feature → probably not much if coverage.py is used
  • implementing it externally (like a shell/python script, pytest plugin or something else) → it is already implemented in coverage.py so it should not be too difficult to add

Summary

These questions should be answered:

  • why is the feature needed? User convenience
  • what problem does it solve? User friendly
  • how it is better compared to past solutions to the problem? JSON is easier to read than XML and more common

pedrorrivero avatar Nov 22 '20 05:11 pedrorrivero

There's a suggestion in https://github.com/pytest-dev/pytest-cov/issues/337 that pytest-cov should do less, to simplify pytest-cov, and that coverage.py should be used for more things.

hugovk avatar Nov 30 '20 17:11 hugovk

I like what I read @hugovk, thanks for the heads-up!

pedrorrivero avatar Nov 30 '20 18:11 pedrorrivero

Given that issue has been open for three and a half years with no traction, I think support for JSON should be implemented in this plugin. What kind of overhead is there? I'd be happy to do the work to contribute it.

mwgamble avatar Feb 27 '23 09:02 mwgamble

Turns out the implementation wasn't very complicated, so I went ahead and did it: https://github.com/pytest-dev/pytest-cov/pull/582

I appreciate the points made in #337, but I think the consensus there is that the maintainers should build a new library that does less, rather than releasing a new major version of this library that's essentially a totally different project anyway. Therefore I think it's appropriate that straightforward modifications to expose additional trivial functionality in coverage.py should still be added to this project.

mwgamble avatar Feb 27 '23 09:02 mwgamble

Thansk a lot @mwgamble!

I agree with your assessment, especially after looking at your implementation (which is simple enough).

pedrorrivero avatar Feb 27 '23 12:02 pedrorrivero

Help me understand why running coverage json is difficult? You can already get a JSON report that way.

nedbat avatar Feb 27 '23 12:02 nedbat

Help me understand why running coverage json is difficult?

  • It's an additional step. Having pytest just generate the JSON file automatically is much more convenient, for the same reasons anyone would already be using any of the other reporters by way of --cov-report.
  • It's not obvious to inexperienced developers why they can't run --cov-report=json when the coverage.py documentation is telling them JSON reporting is fully supported.

mwgamble avatar Feb 27 '23 13:02 mwgamble