Comments (8)
Removing version: 3.0.1 (automated comment)
from coveragepy.
One last interesting detail: nose monkeypatches doctest, so even on Python 2.4, if you use nose to run your tests, all your code will be covered.
from coveragepy.
For completeness: it seems that this flaw was introduced in Python 2.4 and fixed in Python 2.5, so only Python 2.4 is affected.
from coveragepy.
This is a flaw in doctest that was fixed in Python 2.5. If you need to, you can patch doctest.py yourself with this patch: http://svn.zope.org/Zope3/trunk/src/zope/testing/doctest.py?rev=28679&r1=28703&r2=28705
from coveragepy.
Original comment by Anonymous
Hello Dears,
First of all, thanks Ned for your coverage tool.
I have made a simple example for you that is using doctests. The results shown by coverage are not ok unfortunately:
check_doctest_coverage.py:
#!python
def return_arg_or_void(arg):
"""If <arg> is None, return "Void"; otherwise return <arg>
>>> return_arg_or_void(None)
'Void'
>>> return_arg_or_void("arg")
'arg'
>>> return_arg_or_void("None")
'None'
"""
if arg is None:
return "Void"
else:
return arg
if __name__ == "__main__":
import doctest
doctest.testmod()
When you run python check_doctest_coverage.py -v
Trying:
return_arg_or_void(None)
Expecting:
'Void'
ok
Trying:
return_arg_or_void("arg")
Expecting:
'arg'
ok
Trying:
return_arg_or_void("None")
Expecting:
'None'
ok
1 items had no tests:
__main__
1 items passed all tests:
3 tests in __main__.return_arg_or_void
3 tests in 2 items.
3 passed and 0 failed.
Test passed.
When you annotate the file with coverage annotate -d res check_doctest_coverage.py
> def return_arg_or_void(arg):
> """If <arg> is None, return "Void"; otherwise return <arg>
> >>> return_arg_or_void(None)
> 'Void'
> >>> return_arg_or_void("arg")
> 'arg'
> >>> return_arg_or_void("None")
> 'None'
> """
> if arg is None:
> return "Void"
! else:
! return arg
> if __name__ == "__main__":
> import doctest
> doctest.testmod()
So the else part is reported as not executed, although it is (the run of doctest reported 3 successful tests)
Kind regards,
-- Frederic F. M
from coveragepy.
Do you have an example I can use? I don't use doctests myself, so it's very likely I've overlooked something.
from coveragepy.
Original comment by Larry Gilbert (Bitbucket: l2g, GitHub: l2g)
You're right, it wouldn't make sense to expect the doctest lines themselves to show up as covered.
The problem I encountered was that lines of code tested //with// doctest were not being highlighted correctly. I will try to work up an example for you.
Incidentally, I've been trying out nose for tests, which as you probably know uses coverage.py for its coverage reports. nosetests has an option to include doctest test runs when calculating covered code. This did what I expected in the first place. So maybe I am expecting it to be coverage.py's job when it really is up to something like nose. I'm still a rookie at all of this. :-)
from coveragepy.
If I understand what you mean, coverage.py won't indentify the lines in the doctests as executable. This is because they aren't executable: it's the doctest module that pre-processes the docstring and executes it.
Or do you mean that your product code executed by doctests is not identified as executed?
If the first, I wouldn't have thought this would be a problem, since doctests don't typically include conditionals that would make coverage testing important.
If the latter, please provide a small code sample.
from coveragepy.
Related Issues (20)
- coverage report might raise FileNotFoundError when test patches glob HOT 3
- Can we add a json schema to complete pyproject.toml's [tool.coverage]?
- Test suite gets stuck when running on Windows PyPy 7.3.15 HOT 10
- test suite gets really slow in pypy3.9-v7.3.15 on ubuntu 22.04.3 HOT 4
- notes on our experience upgrading coverage 5.4 -> 7.4 HOT 1
- Question: Can `no-cover` "cover" the rest of the function? HOT 2
- Question: How to get the coverage data for each incoming request on my web server. HOT 2
- "No data was collected" when passing --source containing new line separated list HOT 5
- Question: how to add a middleware located on a different folder in settings.py ? HOT 1
- How to exclude external packages from coverage report when using coverage.py API ? HOT 1
- Use PEP 669 Low Impact Monitoring to reduce overhead HOT 3
- How to automate a coverage report using .coveragerc file HOT 1
- How to only show functions that hasn't been covered? HOT 1
- Relative paths duplicates paths on Windows HOT 9
- Facing issue No source for code while combining multiple coverage files HOT 5
- Exclude_lines unable to exclude entire if block from coverage.py in 5.5 version. HOT 5
- Option to record and report classes and imports not used at runtime HOT 1
- Current approach to restarting data collection? HOT 1
- Want to get coverage for 3rd party dependencies' code used by my project. HOT 9
- Coverage html complains about parsing Aenum's _py2.py HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coveragepy.