You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add note to docs about pytest-cov and pytest doctest support #101
A coworker of mine was shocked that the built-in pytest doctest support module didn't integrate with pytest-cov. He wrote a shim to get things working. I was shocked too: I am pretty sure things already work, if you use the arguments in the right combination.
Seems like the gist is just to make sure you have "--doctest-modules" and "--cov" arguments, in your command (or config file).
like ...
py.test foo --cov=foo --doctest-modules
(EDIT -- my previous command example WORKED but it was misleading as to what was going on. command should now be more clear.*)
I think he was forgetting --cov argument and confusing himself. A hint in the docs might help folks avoid this blunder going forward.
So maybe it would be good to just include a usage example like the above, in some docs somewhere. When you look for "doctest" in the pytest-cov docs you don't find anything. Maybe this little FAQ or footnote should be stuffed somewhere, so that searching the pytest-cov docs for "doctest" brings up a hint.
Happy to make a PR... just unclear where to stick this.
Hey. So having something like "pytest-cov will work with doctests if they are in docstrings and --cov (or coverage configuration) matches the containing module"?
Yes, something quick like you mentioned ... maybe just a bit more detailed or search-able:
pytest-cov will work with pytest's built-in doctest support. --cov=<module> (or coverage configuration) should "just work" when you add the --doctest-modules argument. (If it does not, please submit an issue on GitHub and we'll try to get to the bottom of it.) However, your mileage may vary if you are trying to use the --doctest-glob argument. Prefer using --doctest-modules if you can.
The doctest support comes from the official/out-of-the-box plugin, _pytest.doctest (docs). Source code is here. Assuming there's fine coverage of the doctest module, upstream ... I'm not sure we need to add unit tests before adding this little tip to the docs (but I'm all ears)
@ionelmc given my last comment/two ... do you think we need to add unit tests before adding the tip to the documentation -- or can we just go ahead and add the tip?
Oooops, looks like I was wrong. Sorry for making you do the PR. I did some local tests, docstrings are always going to appear as "covered". Doctests are in docstrings so they always get 100% coverage.
Eg, try this and you'll see coverage is 100% which is wrong:
Activity
floer32 commentedon Dec 16, 2015
Could be related: #98
ionelmc commentedon Dec 16, 2015
Hey. So having something like "pytest-cov will work with doctests if they are in docstrings and
--cov(or coverage configuration) matches the containing module"?ionelmc commentedon Dec 16, 2015
I'm not sure how it even works (maybe pytest does some fancypants trickery to exec the code). We should have some tests, just in case.
floer32 commentedon Dec 16, 2015
Yes, something quick like you mentioned ... maybe just a bit more detailed or search-able:
floer32 commentedon Dec 16, 2015
As for fancypants trickery ...
The doctest support comes from the official/out-of-the-box plugin,
_pytest.doctest(docs). Source code is here. Assuming there's fine coverage of the doctest module, upstream ... I'm not sure we need to add unit tests before adding this little tip to the docs (but I'm all ears)floer32 commentedon Dec 31, 2015
@ionelmc given my last comment/two ... do you think we need to add unit tests before adding the tip to the documentation -- or can we just go ahead and add the tip?
ionelmc commentedon Dec 31, 2015
Go ahead and change the docs. I'll take a look at the test part.
ionelmc commentedon Jan 6, 2016
Oooops, looks like I was wrong. Sorry for making you do the PR. I did some local tests, docstrings are always going to appear as "covered". Doctests are in docstrings so they always get 100% coverage.
Eg, try this and you'll see coverage is 100% which is wrong: