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: Cannot doctest a SyntaxError
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: edloper Nosy List: edloper, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2004-08-16 00:20 by rhettinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg22073 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-16 00:20
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
msg22074 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-08-16 00:33
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.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40763
2004-08-16 00:20:23rhettingercreate