summaryrefslogtreecommitdiffstats
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorEdward Loper <edloper@gradient.cis.upenn.edu>2004-09-13 05:47:24 (GMT)
committerEdward Loper <edloper@gradient.cis.upenn.edu>2004-09-13 05:47:24 (GMT)
commit32ddbf7fab000af7941983ecbfe05efd15700255 (patch)
treeeec14f7dd656376fdc92f29c22b6957049a59b19 /Lib/doctest.py
parentc56847878e503ddea8309b0a0c45e06d7c56f2ee (diff)
downloadcpython-32ddbf7fab000af7941983ecbfe05efd15700255.zip
cpython-32ddbf7fab000af7941983ecbfe05efd15700255.tar.gz
cpython-32ddbf7fab000af7941983ecbfe05efd15700255.tar.bz2
Added new parameter exclude_empty to DocTestFinder.__init__, which
controls whether tests are included for objects with empty docstrings. Defaults to True, to match the behavior of Python 2.3.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 2aa7408..156ef57 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -848,7 +848,8 @@ class DocTestFinder:
"""
def __init__(self, verbose=False, parser=DocTestParser(),
- recurse=True, _namefilter=None):
+ recurse=True, _namefilter=None,
+ exclude_empty=False):
"""
Create a new doctest finder.
@@ -860,10 +861,14 @@ class DocTestFinder:
If the optional argument `recurse` is false, then `find` will
only examine the given object, and not any contained objects.
+
+ If the optional argument `exclude_empty` is true, then `find`
+ will exclude tests for objects with empty docstrings.
"""
self._parser = parser
self._verbose = verbose
self._recurse = recurse
+ self._exclude_empty = exclude_empty
# _namefilter is undocumented, and exists only for temporary backward-
# compatibility support of testmod's deprecated isprivate mess.
self._namefilter = _namefilter
@@ -1055,18 +1060,19 @@ class DocTestFinder:
else:
try:
if obj.__doc__ is None:
- return None
- docstring = str(obj.__doc__)
+ docstring = ''
+ else:
+ docstring = str(obj.__doc__)
except (TypeError, AttributeError):
- return None
-
- # Don't bother if the docstring is empty.
- if not docstring:
- return None
+ docstring = ''
# Find the docstring's location in the file.
lineno = self._find_lineno(obj, source_lines)
+ # Don't bother if the docstring is empty.
+ if self._exclude_empty and not docstring:
+ return None
+
# Return a DocTest for this object.
if module is None:
filename = None