[ python-Bugs-1009729 ] Cannot doctest a SyntaxError
SourceForge.net
noreply at sourceforge.net
Mon Aug 16 02:33:57 CEST 2004
Bugs item #1009729, was opened at 2004-08-15 20:20
Message generated for change (Comment added) made by tim_one
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1009729&group_id=5470
Category: Python Library
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Edward Loper (edloper)
Summary: Cannot doctest a SyntaxError
Initial Comment:
Currently, doctests cannot be used to demonstrate or
test that misconstructions produce a syntax error. I'm
not certain, but I believe that case is trappable and
veriable.
The following is an actual use case for one of the
tests I would like to have in test.test_genexps.py:
Verify that parenthesis are required in a statement
>>> def f(n):
... return i*i for i in xrange(n)
...
SyntaxError: invalid syntax
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2004-08-15 20:33
Message:
Logged In: YES
user_id=31435
doctest has always been able to handle SyntaxError; e.g.,
see test_generators.py.
You need a "Traceback:" line too. This is explained in detail
in the current (CVS) doctest LaTeX docs.
For example, this spelling works fine as a doctest:
"""
>>> def f(n):
... return i*i for i in xrange(n)
Traceback (most recent call last):
...
SyntaxError: invalid syntax
"""
You can take out the ellipsis between Traceback and
SyntaxError if you like. You can also keep your "extra"
sys.PS2 line if you like.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1009729&group_id=5470
More information about the Python-bugs-list
mailing list