A simple way to include context on unittest coverage
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 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 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 Use the --show-contexts option to the "coverage html" command. There isn't a way to specify this option through pytest-cov.
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
Feel free to make a PR with the docs change.
I'm happy to do that, @ionelmc.
Does that imply any answer to my questions about setting options? 😉