doctest bug with nested triple quotes

Peter Otten __peter__ at web.de
Tue Aug 2 02:19:01 EDT 2005


Michele Simionato wrote:

> I am getting trouble with nested triple quoted strings in doctest.
> For instance
> 
> $ cat x.py
> """
>>>> dummy = '''
> something
> here
> '''
> """
> import doctest; doctest.testmod()
> 
> $ python x.py
> 
> **********************************************************************
> File "x.py", line 2, in __main__
> Failed example:
>     dummy = '''
> Exception raised:
>     Traceback (most recent call last):
>       File "/usr/lib/python2.4/doctest.py", line 1243, in __run
>         compileflags, 1) in test.globs
>       File "<doctest __main__[0]>", line 1
>          dummy = '''
>                   ^
>      SyntaxError: EOF while scanning triple-quoted string
> **********************************************************************
> 
> Is this a know bug? Any workaround? Thanks for comments,

I think it is your bug. All lines but the first must be prefixed with
sys.PS2. Just add some dots to make it work:

'''
>>> dummy = """
... something
... here
... """
'''
import doctest; doctest.testmod()

Peter



More information about the Python-list mailing list