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

A simple way to include context on unittest coverage

Open sansalinas opened this issue 6 years ago • 6 comments

Hi, here you can find a simple way to include context info into a project for our unittext, I read in some post about it was not clear how context was going to be used, I generate this simple script to make a demo about the way that I use, similar that php coverage report is done.

https://github.com/sansalinas/coverage-context-report

Maybe would be better include into coverage HTML report a dropdown with all contexts and color lines according the selected one, but this is my first approach.

Take in consideration this the first time that I work with python :S (I have started 3 weeks ago) and sorry for my English

sansalinas avatar Dec 10 '19 15:12 sansalinas

@sansalinas Thanks for doing this! It's very helpful to have people trying out ways to use the data. Since 5.0a7 was released, I've added better context reporting to the built-in coverage.py HTML report. Starting in 5.0b1, there's a "ctx" marker at the right edge that opens to list the contexts.

I'd love to hear what you think. It can probably use some finesse.

nedbat avatar Dec 10 '19 20:12 nedbat

@nedbat How can I see the above "ctx" marker? Can you please share a screenshot?

I've ran my test with dynamic context enabled and generated the report with coverage html, but I see no context markers...

undera avatar Feb 03 '20 11:02 undera

@undera Use the --show-contexts option to the "coverage html" command. There isn't a way to specify this option through pytest-cov.

nedbat avatar Feb 04 '20 21:02 nedbat

Could pytest-cov automatically set show_contexts = True when --cov-context=test and --cov-report=html? Or, could it be an option like --cov-report=html:show_contexts?

In the meantime, I'm inclined to document the necessary entry in .coveragerc at https://pytest-cov.readthedocs.io/en/latest/contexts.html:

[html]
show_contexts = True

bhrutledge avatar Sep 09 '20 13:09 bhrutledge

Feel free to make a PR with the docs change.

ionelmc avatar Sep 11 '20 08:09 ionelmc

I'm happy to do that, @ionelmc.

Does that imply any answer to my questions about setting options? 😉

bhrutledge avatar Sep 11 '20 12:09 bhrutledge