summaryrefslogtreecommitdiffstats
path: root/Doc/library/doctest.rst
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2010-06-12 13:42:46 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2010-06-12 13:42:46 (GMT)
commit5e76e94fd45711d65b2f0958b090913e3eff5f49 (patch)
treebd166764c61b9317eb1c5b311e4c9502cad0f95d /Doc/library/doctest.rst
parent0681785d09adb4de0cfd5cdeb2c70d6eeb690dde (diff)
downloadcpython-5e76e94fd45711d65b2f0958b090913e3eff5f49.zip
cpython-5e76e94fd45711d65b2f0958b090913e3eff5f49.tar.gz
cpython-5e76e94fd45711d65b2f0958b090913e3eff5f49.tar.bz2
Merged revisions 80578 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80578 | nick.coghlan | 2010-04-29 00:29:06 +1000 (Thu, 29 Apr 2010) | 1 line Issue 7490: make IGNORE_EXCEPTION_DETAIL also ignore details of the module containing the exception under test (original patch by Lennart Regebro) ........
Diffstat (limited to 'Doc/library/doctest.rst')
-rw-r--r--Doc/library/doctest.rst40
1 files changed, 29 insertions, 11 deletions
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 8967929..3ecbdd0 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -444,8 +444,9 @@ Some details you should read once, but won't need to remember:
with an alphanumeric is taken to be the start of the exception detail. Of
course this does the right thing for genuine tracebacks.
-* When the :const:`IGNORE_EXCEPTION_DETAIL` doctest option is is specified,
- everything following the leftmost colon is ignored.
+* When the :const:`IGNORE_EXCEPTION_DETAIL` doctest option is specified,
+ everything following the leftmost colon and any module information in the
+ exception name is ignored.
* The interactive shell omits the traceback header line for some
:exc:`SyntaxError`\ s. But doctest uses the traceback header line to
@@ -535,20 +536,38 @@ doctest decides whether actual output matches an example's expected output:
exception raised is ``ValueError: 3*14``, but will fail, e.g., if
:exc:`TypeError` is raised.
- Note that a similar effect can be obtained using :const:`ELLIPSIS`, and
- :const:`IGNORE_EXCEPTION_DETAIL` may go away when Python releases prior to 2.4
- become uninteresting. Until then, :const:`IGNORE_EXCEPTION_DETAIL` is the only
- clear way to write a doctest that doesn't care about the exception detail yet
- continues to pass under Python releases prior to 2.4 (doctest directives appear
- to be comments to them). For example, ::
+ It will also ignore the module name used in Python 3 doctest reports. Hence
+ both these variations will work regardless of whether the test is run under
+ Python 2.7 or Python 3.2 (or later versions):
+
+ >>> raise CustomError('message') #doctest: +IGNORE_EXCEPTION_DETAIL
+ Traceback (most recent call last):
+ CustomError: message
+
+ >>> raise CustomError('message') #doctest: +IGNORE_EXCEPTION_DETAIL
+ Traceback (most recent call last):
+ my_module.CustomError: message
+
+ Note that :const:`ELLIPSIS` can also be used to ignore the
+ details of the exception message, but such a test may still fail based
+ on whether or not the module details are printed as part of the
+ exception name. Using :const:`IGNORE_EXCEPTION_DETAIL` and the details
+ from Python 2.3 is also the only clear way to write a doctest that doesn't
+ care about the exception detail yet continues to pass under Python 2.3 or
+ earlier (those releases do not support doctest directives and ignore them
+ as irrelevant comments). For example, ::
>>> (1, 2)[3] = 'moo' #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
- passes under Python 2.4 and Python 2.3. The detail changed in 2.4, to say "does
- not" instead of "doesn't".
+ passes under Python 2.3 and later Python versions, even though the detail
+ changed in Python 2.4 to say "does not" instead of "doesn't".
+
+ .. versionchanged:: 3.2
+ :const:`IGNORE_EXCEPTION_DETAIL` now also ignores any information
+ relating to the module containing the exception under test
.. data:: SKIP
@@ -663,7 +682,6 @@ usually the only meaningful choice. However, option flags can also be passed to
functions that run doctests, establishing different defaults. In such cases,
disabling an option via ``-`` in a directive can be useful.
-
There's also a way to register new option flag names, although this isn't useful
unless you intend to extend :mod:`doctest` internals via subclassing: