@@ -318,7 +318,8 @@ The fine print:
318318 Tabs in output generated by the tested code are not modified. Because any
319319 hard tabs in the sample output *are * expanded, this means that if the code
320320 output includes hard tabs, the only way the doctest can pass is if the
321- :const: `NORMALIZE_WHITESPACE ` option or directive is in effect.
321+ :const: `NORMALIZE_WHITESPACE ` option or :ref: `directive <doctest-directives >`
322+ is in effect.
322323 Alternatively, the test can be rewritten to capture the output and compare it
323324 to an expected value as part of the test. This handling of tabs in the
324325 source was arrived at through trial and error, and has proven to be the least
@@ -483,15 +484,16 @@ Some details you should read once, but won't need to remember:
483484 SyntaxError: invalid syntax
484485
485486
487+ .. _option-flags-and-directives :
486488.. _doctest-options :
487489
488- Option Flags and Directives
489- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
490+ Option Flags
491+ ^^^^^^^^^^^^
490492
491493A number of option flags control various aspects of doctest's behavior.
492494Symbolic names for the flags are supplied as module constants, which can be
493495or'ed together and passed to various functions. The names can also be used in
494- doctest directives (see below) .
496+ :ref: ` doctest directives < doctest-directives >` .
495497
496498The first group of options define test semantics, controlling aspects of how
497499doctest decides whether actual output matches an example's expected output:
@@ -545,8 +547,8 @@ doctest decides whether actual output matches an example's expected output:
545547 :exc: `TypeError ` is raised.
546548
547549 It will also ignore the module name used in Python 3 doctest reports. Hence
548- both these variations will work regardless of whether the test is run under
549- Python 2.7 or Python 3.2 (or later versions):
550+ both of these variations will work with the flag specified, regardless of
551+ whether the test is run under Python 2.7 or Python 3.2 (or later versions): :
550552
551553 >>> raise CustomError('message') #doctest: +IGNORE_EXCEPTION_DETAIL
552554 Traceback (most recent call last):
@@ -562,15 +564,16 @@ doctest decides whether actual output matches an example's expected output:
562564 exception name. Using :const: `IGNORE_EXCEPTION_DETAIL ` and the details
563565 from Python 2.3 is also the only clear way to write a doctest that doesn't
564566 care about the exception detail yet continues to pass under Python 2.3 or
565- earlier (those releases do not support doctest directives and ignore them
566- as irrelevant comments). For example, ::
567+ earlier (those releases do not support :ref: ` doctest directives
568+ <doctest-directives>` and ignore them as irrelevant comments). For example::
567569
568570 >>> (1 , 2 )[3 ] = ' moo' # doctest: +IGNORE_EXCEPTION_DETAIL
569571 Traceback (most recent call last):
570572 File "<stdin>", line 1, in ?
571573 TypeError: object doesn't support item assignment
572574
573- passes under Python 2.3 and later Python versions, even though the detail
575+ passes under Python 2.3 and later Python versions with the flag specified,
576+ even though the detail
574577 changed in Python 2.4 to say "does not" instead of "doesn't".
575578
576579 .. versionchanged :: 3.2
@@ -632,9 +635,30 @@ The second group of options controls how test failures are reported:
632635
633636 A bitmask or'ing together all the reporting flags above.
634637
635- "Doctest directives" may be used to modify the option flags for individual
636- examples. Doctest directives are expressed as a special Python comment
637- following an example's source code:
638+
639+ There is also a way to register new option flag names, though this isn't
640+ useful unless you intend to extend :mod: `doctest ` internals via subclassing:
641+
642+
643+ .. function :: register_optionflag(name)
644+
645+ Create a new option flag with a given name, and return the new flag's integer
646+ value. :func: `register_optionflag ` can be used when subclassing
647+ :class: `OutputChecker ` or :class: `DocTestRunner ` to create new options that are
648+ supported by your subclasses. :func: `register_optionflag ` should always be
649+ called using the following idiom::
650+
651+ MY_FLAG = register_optionflag('MY_FLAG')
652+
653+
654+ .. _doctest-directives :
655+
656+ Directives
657+ ^^^^^^^^^^
658+
659+ Doctest directives may be used to modify the :ref: `option flags
660+ <doctest-options>` for an individual example. Doctest directives are
661+ special Python comments following an example's source code:
638662
639663.. productionlist :: doctest
640664 directive: "#" "doctest:" `directive_options `
@@ -708,20 +732,6 @@ usually the only meaningful choice. However, option flags can also be passed to
708732functions that run doctests, establishing different defaults. In such cases,
709733disabling an option via ``- `` in a directive can be useful.
710734
711- There's also a way to register new option flag names, although this isn't useful
712- unless you intend to extend :mod: `doctest ` internals via subclassing:
713-
714-
715- .. function :: register_optionflag(name)
716-
717- Create a new option flag with a given name, and return the new flag's integer
718- value. :func: `register_optionflag ` can be used when subclassing
719- :class: `OutputChecker ` or :class: `DocTestRunner ` to create new options that are
720- supported by your subclasses. :func: `register_optionflag ` should always be
721- called using the following idiom::
722-
723- MY_FLAG = register_optionflag('MY_FLAG')
724-
725735
726736.. _doctest-warnings :
727737
@@ -759,7 +769,9 @@ Another bad idea is to print things that embed an object address, like ::
759769 >>> C() # the default repr() for instances embeds an address
760770 <__main__.C instance at 0x00AC18F0>
761771
762- The :const: `ELLIPSIS ` directive gives a nice approach for the last example::
772+ The :const: `ELLIPSIS ` directive gives a nice approach for the last example:
773+
774+ .. code-block :: text
763775
764776 >>> C() #doctest: +ELLIPSIS
765777 <__main__.C instance at 0x...>
0 commit comments