This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: doctest handles comments incorrectly
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: aschmolck, rhettinger, tim.peters
Priority: normal Keywords: patch

Created on 2003-01-15 14:39 by aschmolck, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
doctest.py.PATCH aschmolck, 2003-01-16 12:40
Messages (4)
msg42430 - (view) Author: Alexander Schmolck (aschmolck) Date: 2003-01-15 14:39
> >    import doctest, test
> >    def aTest():
> >        r""">>> # A comment
> >            ... print 'This is incorrectly ignored
by doctest'
> >            This output here really doesn't matter
either... (but SHOULD)
> >            >>>
> >            """

the patch fixes that and passes the original doctest
tests. (test_doctest and doctest.py itself)
msg42431 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-01-16 01:56
Logged In: YES 
user_id=80475

The file attachment didn't make it.
msg42432 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-01-16 02:45
Logged In: YES 
user_id=31435

Alexander, you need to check the "Check to Upload and 
Attach a File" box when trying to attach a file.  This is a 
SourceForge annoyance we have no control over.  Please 
try again!
msg42433 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-02-17 00:41
Logged In: YES 
user_id=31435

It's intentional that doctest looks for PS1 to identify lines that 
begin Python statements, and I'm opposed to changing that.  
The docs could be clearer on this point.  I don't care that the 
Python command-line shell is braindead in starting a line 
following a comment with PS2.  The IDLE shell, and the 
PythonWin shell, are not insane in this respect, and I don't 
want doctest to be in the business of guessing intent across 
the union of all stupid things all Python shells do.  As the docs 
say, "In most cases a copy-and-paste of an interactive
console session works fine".  "most" < "all", because of goofy 
exceptions like this one.  doctest has its own rules for 
distinguishing among intial lines, continuation lines, and output 
lines, and I want to keep them as simple as they are.

In your specific example, change the doctest to use PS1 
instead of PS2 on the 'print' line, and it should work fine.

While I'm rejecting this patch, I'd be happy to see a patch to 
make the Python command-line shell smarter in this case.
History
Date User Action Args
2022-04-10 16:06:08adminsetgithub: 37774
2003-01-15 14:39:52aschmolckcreate