@@ -444,8 +444,9 @@ Some details you should read once, but won't need to remember:
444444 with an alphanumeric is taken to be the start of the exception detail. Of
445445 course this does the right thing for genuine tracebacks.
446446
447- * When the :const: `IGNORE_EXCEPTION_DETAIL ` doctest option is is specified,
448- everything following the leftmost colon is ignored.
447+ * When the :const: `IGNORE_EXCEPTION_DETAIL ` doctest option is specified,
448+ everything following the leftmost colon and any module information in the
449+ exception name is ignored.
449450
450451* The interactive shell omits the traceback header line for some
451452 :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:
535536 exception raised is ``ValueError: 3*14 ``, but will fail, e.g., if
536537 :exc: `TypeError ` is raised.
537538
538- Note that a similar effect can be obtained using :const: `ELLIPSIS `, and
539- :const: `IGNORE_EXCEPTION_DETAIL ` may go away when Python releases prior to 2.4
540- become uninteresting. Until then, :const: `IGNORE_EXCEPTION_DETAIL ` is the only
541- clear way to write a doctest that doesn't care about the exception detail yet
542- continues to pass under Python releases prior to 2.4 (doctest directives appear
543- to be comments to them). For example, ::
539+ It will also ignore the module name used in Python 3 doctest reports. Hence
540+ both these variations will work regardless of whether the test is run under
541+ Python 2.7 or Python 3.2 (or later versions):
542+
543+ >>> raise CustomError(' message' ) # doctest: +IGNORE_EXCEPTION_DETAIL
544+ Traceback (most recent call last):
545+ CustomError: message
546+
547+ >>> raise CustomError(' message' ) # doctest: +IGNORE_EXCEPTION_DETAIL
548+ Traceback (most recent call last):
549+ my_module.CustomError: message
550+
551+ Note that :const: `ELLIPSIS ` can also be used to ignore the
552+ details of the exception message, but such a test may still fail based
553+ on whether or not the module details are printed as part of the
554+ exception name. Using :const: `IGNORE_EXCEPTION_DETAIL ` and the details
555+ from Python 2.3 is also the only clear way to write a doctest that doesn't
556+ care about the exception detail yet continues to pass under Python 2.3 or
557+ earlier (those releases do not support doctest directives and ignore them
558+ as irrelevant comments). For example, ::
544559
545560 >>> (1, 2)[3] = 'moo' #doctest: +IGNORE_EXCEPTION_DETAIL
546561 Traceback (most recent call last):
547562 File "<stdin>", line 1, in ?
548563 TypeError: object doesn't support item assignment
549564
550- passes under Python 2.4 and Python 2.3. The detail changed in 2.4, to say "does
551- not" instead of "doesn't".
565+ passes under Python 2.3 and later Python versions, even though the detail
566+ changed in Python 2.4 to say "does not" instead of "doesn't".
567+
568+ .. versionchanged :: 3.2
569+ :const: `IGNORE_EXCEPTION_DETAIL ` now also ignores any information
570+ relating to the module containing the exception under test
552571
553572
554573.. data :: SKIP
@@ -663,7 +682,6 @@ usually the only meaningful choice. However, option flags can also be passed to
663682functions that run doctests, establishing different defaults. In such cases,
664683disabling an option via ``- `` in a directive can be useful.
665684
666-
667685There's also a way to register new option flag names, although this isn't useful
668686unless you intend to extend :mod: `doctest ` internals via subclassing:
669687
0 commit comments