Skip to content

Commit d9254f9

Browse files
hugovkAlexWaygood
andauthored
[3.11] gh-101100 : Fix Sphinx warnings in library/doctest.rst (GH-112399) (#112404)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 8c9f273 commit d9254f9

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

Doc/library/doctest.rst

+27-20
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ Simple Usage: Checking Examples in Docstrings
143143
---------------------------------------------
144144

145145
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::
147147

148148
if __name__ == "__main__":
149149
import doctest
150150
doctest.testmod()
151151

152-
:mod:`doctest` then examines docstrings in module :mod:`M`.
152+
:mod:`!doctest` then examines docstrings in module :mod:`!M`.
153153

154154
Running the module as a script causes the examples in the docstrings to get
155155
executed and verified::
@@ -401,10 +401,10 @@ What's the Execution Context?
401401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
402402

403403
By default, each time :mod:`doctest` finds a docstring to test, it uses a
404-
*shallow copy* of :mod:`M`'s globals, so that running tests doesn't change the
405-
module's real globals, and so that one test in :mod:`M` can't leave behind
404+
*shallow copy* of :mod:`!M`'s globals, so that running tests doesn't change the
405+
module's real globals, and so that one test in :mod:`!M` can't leave behind
406406
crumbs that accidentally allow another test to work. This means examples can
407-
freely use any names defined at top-level in :mod:`M`, and names defined earlier
407+
freely use any names defined at top-level in :mod:`!M`, and names defined earlier
408408
in the docstring being run. Examples cannot see names defined in other
409409
docstrings.
410410

@@ -956,7 +956,8 @@ and :ref:`doctest-simple-testfile`.
956956

957957
Optional argument *exclude_empty* defaults to false. If true, objects for which
958958
no doctests are found are excluded from consideration. The default is a backward
959-
compatibility hack, so that code still using :meth:`doctest.master.summarize` in
959+
compatibility hack, so that code still using
960+
:meth:`doctest.master.summarize <DocTestRunner.summarize>` in
960961
conjunction with :func:`testmod` continues to get output for objects with no
961962
tests. The *exclude_empty* argument to the newer :class:`DocTestFinder`
962963
constructor defaults to true.
@@ -995,7 +996,7 @@ As your collection of doctest'ed modules grows, you'll want a way to run all
995996
their doctests systematically. :mod:`doctest` provides two functions that can
996997
be used to create :mod:`unittest` test suites from modules and text files
997998
containing doctests. To integrate with :mod:`unittest` test discovery, include
998-
a :func:`load_tests` function in your test module::
999+
a :ref:`load_tests <load_tests-protocol>` function in your test module::
9991000

10001001
import unittest
10011002
import doctest
@@ -1109,19 +1110,24 @@ from text files and modules with doctests:
11091110
:func:`DocTestSuite` returns an empty :class:`unittest.TestSuite` if *module*
11101111
contains no docstrings instead of raising :exc:`ValueError`.
11111112

1113+
.. exception:: failureException
1114+
1115+
When doctests which have been converted to unit tests by :func:`DocFileSuite`
1116+
or :func:`DocTestSuite` fail, this exception is raised showing the name of
1117+
the file containing the test and a (sometimes approximate) line number.
11121118

11131119
Under the covers, :func:`DocTestSuite` creates a :class:`unittest.TestSuite` out
1114-
of :class:`doctest.DocTestCase` instances, and :class:`DocTestCase` is a
1115-
subclass of :class:`unittest.TestCase`. :class:`DocTestCase` isn't documented
1120+
of :class:`!doctest.DocTestCase` instances, and :class:`!DocTestCase` is a
1121+
subclass of :class:`unittest.TestCase`. :class:`!DocTestCase` isn't documented
11161122
here (it's an internal detail), but studying its code can answer questions about
11171123
the exact details of :mod:`unittest` integration.
11181124

11191125
Similarly, :func:`DocFileSuite` creates a :class:`unittest.TestSuite` out of
1120-
:class:`doctest.DocFileCase` instances, and :class:`DocFileCase` is a subclass
1121-
of :class:`DocTestCase`.
1126+
:class:`!doctest.DocFileCase` instances, and :class:`!DocFileCase` is a subclass
1127+
of :class:`!DocTestCase`.
11221128

11231129
So both ways of creating a :class:`unittest.TestSuite` run instances of
1124-
:class:`DocTestCase`. This is important for a subtle reason: when you run
1130+
:class:`!DocTestCase`. This is important for a subtle reason: when you run
11251131
:mod:`doctest` functions yourself, you can control the :mod:`doctest` options in
11261132
use directly, by passing option flags to :mod:`doctest` functions. However, if
11271133
you're writing a :mod:`unittest` framework, :mod:`unittest` ultimately controls
@@ -1142,14 +1148,14 @@ reporting flags specific to :mod:`unittest` support, via this function:
11421148
section :ref:`doctest-options`. Only "reporting flags" can be used.
11431149

11441150
This is a module-global setting, and affects all future doctests run by module
1145-
:mod:`unittest`: the :meth:`runTest` method of :class:`DocTestCase` looks at
1146-
the option flags specified for the test case when the :class:`DocTestCase`
1151+
:mod:`unittest`: the :meth:`!runTest` method of :class:`!DocTestCase` looks at
1152+
the option flags specified for the test case when the :class:`!DocTestCase`
11471153
instance was constructed. If no reporting flags were specified (which is the
1148-
typical and expected case), :mod:`doctest`'s :mod:`unittest` reporting flags are
1154+
typical and expected case), :mod:`!doctest`'s :mod:`unittest` reporting flags are
11491155
:ref:`bitwise ORed <bitwise>` into the option flags, and the option flags
11501156
so augmented are passed to the :class:`DocTestRunner` instance created to
11511157
run the doctest. If any reporting flags were specified when the
1152-
:class:`DocTestCase` instance was constructed, :mod:`doctest`'s
1158+
:class:`!DocTestCase` instance was constructed, :mod:`!doctest`'s
11531159
:mod:`unittest` reporting flags are ignored.
11541160

11551161
The value of the :mod:`unittest` reporting flags in effect before the function
@@ -1319,7 +1325,8 @@ Example Objects
13191325
A dictionary mapping from option flags to ``True`` or ``False``, which is used
13201326
to override default options for this example. Any option flags not contained
13211327
in this dictionary are left at their default value (as specified by the
1322-
:class:`DocTestRunner`'s :attr:`optionflags`). By default, no options are set.
1328+
:class:`DocTestRunner`'s :ref:`optionflags <doctest-options>`).
1329+
By default, no options are set.
13231330

13241331

13251332
.. _doctest-doctestfinder:
@@ -1532,7 +1539,7 @@ DocTestRunner objects
15321539

15331540
The output of each example is checked using the :class:`DocTestRunner`'s
15341541
output checker, and the results are formatted by the
1535-
:meth:`DocTestRunner.report_\*` methods.
1542+
:meth:`!DocTestRunner.report_\*` methods.
15361543

15371544

15381545
.. method:: summarize(verbose=None)
@@ -1690,12 +1697,12 @@ code under the debugger:
16901697
module) of the object with the doctests of interest. The result is a string,
16911698
containing the object's docstring converted to a Python script, as described for
16921699
:func:`script_from_examples` above. For example, if module :file:`a.py`
1693-
contains a top-level function :func:`f`, then ::
1700+
contains a top-level function :func:`!f`, then ::
16941701

16951702
import a, doctest
16961703
print(doctest.testsource(a, "a.f"))
16971704

1698-
prints a script version of function :func:`f`'s docstring, with doctests
1705+
prints a script version of function :func:`!f`'s docstring, with doctests
16991706
converted to code, and the rest placed in comments.
17001707

17011708

Doc/library/unittest.rst

+2
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,8 @@ Loading and running tests
23322332
test names.
23332333

23342334

2335+
.. _load_tests-protocol:
2336+
23352337
load_tests Protocol
23362338
###################
23372339

Doc/tools/.nitignore

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Doc/library/datetime.rst
5252
Doc/library/dbm.rst
5353
Doc/library/decimal.rst
5454
Doc/library/dis.rst
55-
Doc/library/doctest.rst
5655
Doc/library/email.charset.rst
5756
Doc/library/email.compat32-message.rst
5857
Doc/library/email.errors.rst

0 commit comments

Comments
 (0)