@@ -568,41 +568,35 @@ doctest decides whether actual output matches an example's expected output:
568
568
569
569
.. data :: IGNORE_EXCEPTION_DETAIL
570
570
571
- When specified, an example that expects an exception passes if an exception of
572
- the expected type is raised, even if the exception detail does not match. For
573
- example, an example expecting ``ValueError: 42 `` will pass if the actual
574
- exception raised is ``ValueError: 3*14 ``, but will fail, e.g., if
575
- :exc: `TypeError ` is raised.
571
+ When specified, doctests expecting exceptions pass so long as an exception
572
+ of the expected type is raised, even if the details
573
+ (message and fully-qualified exception name) don't match.
576
574
577
- It will also ignore the module name used in Python 3 doctest reports. Hence
578
- both of these variations will work with the flag specified, regardless of
579
- whether the test is run under Python 2.7 or Python 3.2 (or later versions)::
575
+ For example, an example expecting ``ValueError: 42 `` will pass if the actual
576
+ exception raised is ``ValueError: 3*14 ``, but will fail if, say, a
577
+ :exc: `TypeError ` is raised instead.
578
+ It will also ignore any fully-qualified name included before the
579
+ exception class, which can vary between implementations and versions
580
+ of Python and the code/libraries in use.
581
+ Hence, all three of these variations will work with the flag specified:
580
582
581
- >>> raise CustomError('message')
583
+ .. code-block :: pycon
584
+
585
+ >>> raise Exception('message')
582
586
Traceback (most recent call last):
583
- CustomError : message
587
+ Exception : message
584
588
585
- >>> raise CustomError ('message')
589
+ >>> raise Exception ('message')
586
590
Traceback (most recent call last):
587
- my_module.CustomError : message
591
+ builtins.Exception : message
588
592
589
- Note that :const: `ELLIPSIS ` can also be used to ignore the
590
- details of the exception message, but such a test may still fail based
591
- on whether or not the module details are printed as part of the
592
- exception name. Using :const: `IGNORE_EXCEPTION_DETAIL ` and the details
593
- from Python 2.3 is also the only clear way to write a doctest that doesn't
594
- care about the exception detail yet continues to pass under Python 2.3 or
595
- earlier (those releases do not support :ref: `doctest directives
596
- <doctest-directives>` and ignore them as irrelevant comments). For example::
597
-
598
- >>> (1 , 2 )[3 ] = ' moo'
593
+ >>> raise Exception('message')
599
594
Traceback (most recent call last):
600
- File "<stdin>", line 1, in <module>
601
- TypeError: object doesn't support item assignment
595
+ __main__.Exception: message
602
596
603
- passes under Python 2.3 and later Python versions with the flag specified,
604
- even though the detail
605
- changed in Python 2.4 to say "does not" instead of "doesn't" .
597
+ Note that :const: ` ELLIPSIS ` can also be used to ignore the
598
+ details of the exception message, but such a test may still fail based
599
+ on whether the module name is present or matches exactly .
606
600
607
601
.. versionchanged :: 3.2
608
602
:const: `IGNORE_EXCEPTION_DETAIL ` now also ignores any information relating
0 commit comments