@@ -143,13 +143,13 @@ Simple Usage: Checking Examples in Docstrings
143
143
---------------------------------------------
144
144
145
145
The simplest way to start using doctest (but not necessarily the way you'll
146
- continue to do it) is to end each module :mod: `M ` with::
146
+ continue to do it) is to end each module :mod: `! M ` with::
147
147
148
148
if __name__ == "__main__":
149
149
import doctest
150
150
doctest.testmod()
151
151
152
- :mod: `doctest ` then examines docstrings in module :mod: `M `.
152
+ :mod: `! doctest ` then examines docstrings in module :mod: `! M `.
153
153
154
154
Running the module as a script causes the examples in the docstrings to get
155
155
executed and verified::
@@ -403,10 +403,10 @@ What's the Execution Context?
403
403
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
404
404
405
405
By default, each time :mod: `doctest ` finds a docstring to test, it uses a
406
- *shallow copy * of :mod: `M `'s globals, so that running tests doesn't change the
407
- module's real globals, and so that one test in :mod: `M ` can't leave behind
406
+ *shallow copy * of :mod: `! M `'s globals, so that running tests doesn't change the
407
+ module's real globals, and so that one test in :mod: `! M ` can't leave behind
408
408
crumbs that accidentally allow another test to work. This means examples can
409
- freely use any names defined at top-level in :mod: `M `, and names defined earlier
409
+ freely use any names defined at top-level in :mod: `! M `, and names defined earlier
410
410
in the docstring being run. Examples cannot see names defined in other
411
411
docstrings.
412
412
@@ -958,7 +958,8 @@ and :ref:`doctest-simple-testfile`.
958
958
959
959
Optional argument *exclude_empty * defaults to false. If true, objects for which
960
960
no doctests are found are excluded from consideration. The default is a backward
961
- compatibility hack, so that code still using :meth: `doctest.master.summarize ` in
961
+ compatibility hack, so that code still using
962
+ :meth: `doctest.master.summarize <DocTestRunner.summarize> ` in
962
963
conjunction with :func: `testmod ` continues to get output for objects with no
963
964
tests. The *exclude_empty * argument to the newer :class: `DocTestFinder `
964
965
constructor defaults to true.
@@ -997,7 +998,7 @@ As your collection of doctest'ed modules grows, you'll want a way to run all
997
998
their doctests systematically. :mod: `doctest ` provides two functions that can
998
999
be used to create :mod: `unittest ` test suites from modules and text files
999
1000
containing doctests. To integrate with :mod: `unittest ` test discovery, include
1000
- a :func : `load_tests ` function in your test module::
1001
+ a :ref : `load_tests < load_tests-protocol > ` function in your test module::
1001
1002
1002
1003
import unittest
1003
1004
import doctest
@@ -1111,19 +1112,24 @@ from text files and modules with doctests:
1111
1112
:func: `DocTestSuite ` returns an empty :class: `unittest.TestSuite ` if *module *
1112
1113
contains no docstrings instead of raising :exc: `ValueError `.
1113
1114
1115
+ .. exception :: failureException
1116
+
1117
+ When doctests which have been converted to unit tests by :func: `DocFileSuite `
1118
+ or :func: `DocTestSuite ` fail, this exception is raised showing the name of
1119
+ the file containing the test and a (sometimes approximate) line number.
1114
1120
1115
1121
Under the covers, :func: `DocTestSuite ` creates a :class: `unittest.TestSuite ` out
1116
- of :class: `doctest.DocTestCase ` instances, and :class: `DocTestCase ` is a
1117
- subclass of :class: `unittest.TestCase `. :class: `DocTestCase ` isn't documented
1122
+ of :class: `! doctest.DocTestCase ` instances, and :class: `! DocTestCase ` is a
1123
+ subclass of :class: `unittest.TestCase `. :class: `! DocTestCase ` isn't documented
1118
1124
here (it's an internal detail), but studying its code can answer questions about
1119
1125
the exact details of :mod: `unittest ` integration.
1120
1126
1121
1127
Similarly, :func: `DocFileSuite ` creates a :class: `unittest.TestSuite ` out of
1122
- :class: `doctest.DocFileCase ` instances, and :class: `DocFileCase ` is a subclass
1123
- of :class: `DocTestCase `.
1128
+ :class: `! doctest.DocFileCase ` instances, and :class: `! DocFileCase ` is a subclass
1129
+ of :class: `! DocTestCase `.
1124
1130
1125
1131
So both ways of creating a :class: `unittest.TestSuite ` run instances of
1126
- :class: `DocTestCase `. This is important for a subtle reason: when you run
1132
+ :class: `! DocTestCase `. This is important for a subtle reason: when you run
1127
1133
:mod: `doctest ` functions yourself, you can control the :mod: `doctest ` options in
1128
1134
use directly, by passing option flags to :mod: `doctest ` functions. However, if
1129
1135
you're writing a :mod: `unittest ` framework, :mod: `unittest ` ultimately controls
@@ -1144,14 +1150,14 @@ reporting flags specific to :mod:`unittest` support, via this function:
1144
1150
section :ref: `doctest-options `. Only "reporting flags" can be used.
1145
1151
1146
1152
This is a module-global setting, and affects all future doctests run by module
1147
- :mod: `unittest `: the :meth: `runTest ` method of :class: `DocTestCase ` looks at
1148
- the option flags specified for the test case when the :class: `DocTestCase `
1153
+ :mod: `unittest `: the :meth: `! runTest ` method of :class: `! DocTestCase ` looks at
1154
+ the option flags specified for the test case when the :class: `! DocTestCase `
1149
1155
instance was constructed. If no reporting flags were specified (which is the
1150
- typical and expected case), :mod: `doctest `'s :mod: `unittest ` reporting flags are
1156
+ typical and expected case), :mod: `! doctest `'s :mod: `unittest ` reporting flags are
1151
1157
:ref: `bitwise ORed <bitwise >` into the option flags, and the option flags
1152
1158
so augmented are passed to the :class: `DocTestRunner ` instance created to
1153
1159
run the doctest. If any reporting flags were specified when the
1154
- :class: `DocTestCase ` instance was constructed, :mod: `doctest `'s
1160
+ :class: `! DocTestCase ` instance was constructed, :mod: `! doctest `'s
1155
1161
:mod: `unittest ` reporting flags are ignored.
1156
1162
1157
1163
The value of the :mod: `unittest ` reporting flags in effect before the function
@@ -1321,7 +1327,8 @@ Example Objects
1321
1327
A dictionary mapping from option flags to ``True `` or ``False ``, which is used
1322
1328
to override default options for this example. Any option flags not contained
1323
1329
in this dictionary are left at their default value (as specified by the
1324
- :class: `DocTestRunner `'s :attr: `optionflags `). By default, no options are set.
1330
+ :class: `DocTestRunner `'s :ref: `optionflags <doctest-options >`).
1331
+ By default, no options are set.
1325
1332
1326
1333
1327
1334
.. _doctest-doctestfinder :
@@ -1560,7 +1567,7 @@ DocTestRunner objects
1560
1567
1561
1568
The output of each example is checked using the :class: `DocTestRunner `'s
1562
1569
output checker, and the results are formatted by the
1563
- :meth: `DocTestRunner.report_\* ` methods.
1570
+ :meth: `! DocTestRunner.report_\* ` methods.
1564
1571
1565
1572
1566
1573
.. method :: summarize(verbose=None)
@@ -1735,12 +1742,12 @@ code under the debugger:
1735
1742
module) of the object with the doctests of interest. The result is a string,
1736
1743
containing the object's docstring converted to a Python script, as described for
1737
1744
:func: `script_from_examples ` above. For example, if module :file: `a.py `
1738
- contains a top-level function :func: `f `, then ::
1745
+ contains a top-level function :func: `! f `, then ::
1739
1746
1740
1747
import a, doctest
1741
1748
print(doctest.testsource(a, "a.f"))
1742
1749
1743
- prints a script version of function :func: `f `'s docstring, with doctests
1750
+ prints a script version of function :func: `! f `'s docstring, with doctests
1744
1751
converted to code, and the rest placed in comments.
1745
1752
1746
1753
0 commit comments