Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple way to include context on unittest coverage #371

Open
sansalinas opened this issue Dec 10, 2019 · 6 comments
Open

A simple way to include context on unittest coverage #371

sansalinas opened this issue Dec 10, 2019 · 6 comments

Comments

@sansalinas
Copy link

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

@nedbat
Copy link
Collaborator

nedbat commented Dec 10, 2019

@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.

@undera
Copy link

undera commented Feb 3, 2020

@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...

@nedbat
Copy link
Collaborator

nedbat commented Feb 4, 2020

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

@blueyed blueyed changed the title A simple way to include context on unnittest coverage A simple way to include context on unittest coverage Mar 15, 2020
@bhrutledge
Copy link
Contributor

bhrutledge commented Sep 9, 2020

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

@ionelmc
Copy link
Member

ionelmc commented Sep 11, 2020

Feel free to make a PR with the docs change.

@bhrutledge
Copy link
Contributor

I'm happy to do that, @ionelmc.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants