Author cpitclaudel
Recipients cpitclaudel
Date 2016-09-22.15:32:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474558340.5.0.316638267735.issue28249@psf.upfronthosting.co.za>
In-reply-to
Content
Line numbers reported by the doctest module are wrong when a function does not include a docstring.  With the attached example file, running

    python -c "import doctest, example; print(doctest.DocTestFinder(exclude_empty=False).find(example))"

produces

    [<DocTest example from example.py:5 (no examples)>,
     <DocTest example.a from example.py:5 (no examples)>,
     <DocTest example.b from example.py:5 (no examples)>,
     <DocTest example.c from example.py:None (no examples)>]

whereas if one uncomments the docstrings of a and c the output is

    [<DocTest example from example.py:1 (no examples)>,
     <DocTest example.a from example.py:1 (no examples)>,
     <DocTest example.b from example.py:5 (no examples)>,
     <DocTest example.c from example.py:9 (no examples)>]

This bug is due to this line in doctest:

    lineno = self._find_lineno(obj, source_lines)

The documentation of _find_lineno says this:

    def _find_lineno(self, obj, source_lines):
        """
        Return a line number of the given object's docstring.  Note:
        this method assumes that the object has a docstring.
        """

This assumption is violated by the call listed above, because of the exclude_empty=False parameter to DocTestFinder().

I guess lineno should just be None for all methods that do not have a docstring?
History
Date User Action Args
2016-09-22 15:32:20cpitclaudelsetrecipients: + cpitclaudel
2016-09-22 15:32:20cpitclaudelsetmessageid: <1474558340.5.0.316638267735.issue28249@psf.upfronthosting.co.za>
2016-09-22 15:32:20cpitclaudellinkissue28249 messages
2016-09-22 15:32:20cpitclaudelcreate