Skip to content

Commit 8281462

Browse files
authored
Doctest cleanups (GH-95436)
* GHA: Don't hide doctest output * Enable doctests in math.rst * Squash warnings in nntplib.rst doctests * Squash warning in turtle.rst doctest * Squash warnings in whatsnew/3.2.rst doctests * Treat warnings as errors in Doc/ doctests
1 parent 9ec6abf commit 8281462

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ jobs:
7878
run: make -C Doc/ PYTHON=../python venv
7979
# Use "xvfb-run" since some doctest tests open GUI windows
8080
- name: 'Run documentation doctest'
81-
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" doctest
81+
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest

Doc/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
import _tkinter
2323
except ImportError:
2424
_tkinter = None
25+
# Treat warnings as errors, done here to prevent warnings in Sphinx code from
26+
# causing spurious test failures.
27+
import warnings
28+
warnings.simplefilter('error')
29+
del warnings
2530
'''
2631

2732
manpages_url = 'https://manpages.debian.org/{path}'

Doc/library/math.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Number-theoretic and representation functions
108108
.. function:: fsum(iterable)
109109

110110
Return an accurate floating point sum of values in the iterable. Avoids
111-
loss of precision by tracking multiple intermediate partial sums::
111+
loss of precision by tracking multiple intermediate partial sums:
112112

113113
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
114114
0.9999999999999999
@@ -371,7 +371,7 @@ Power and logarithmic functions
371371
logarithms. For small floats *x*, the subtraction in ``exp(x) - 1``
372372
can result in a `significant loss of precision
373373
<https://en.wikipedia.org/wiki/Loss_of_significance>`_\; the :func:`expm1`
374-
function provides a way to compute this quantity to full precision::
374+
function provides a way to compute this quantity to full precision:
375375

376376
>>> from math import exp, expm1
377377
>>> exp(1e-5) - 1 # gives result accurate to 11 places
@@ -654,7 +654,7 @@ Constants
654654
not considered to equal to any other numeric value, including themselves. To check
655655
whether a number is a NaN, use the :func:`isnan` function to test
656656
for NaNs instead of ``is`` or ``==``.
657-
Example::
657+
Example:
658658

659659
>>> import math
660660
>>> math.nan == math.nan

Doc/library/nntplib.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
.. deprecated:: 3.11
1515
The :mod:`nntplib` module is deprecated (see :pep:`594` for details).
1616

17+
.. testsetup::
18+
19+
import warnings
20+
with warnings.catch_warnings():
21+
warnings.simplefilter('ignore', category=DeprecationWarning)
22+
import nntplib
23+
24+
.. testcleanup::
25+
26+
try:
27+
s.quit()
28+
except NameError:
29+
pass
30+
import sys
31+
# Force a warning if any other file imports nntplib
32+
sys.modules.pop('nntplib')
33+
1734
--------------
1835

1936
This module defines the class :class:`NNTP` which implements the client side of

Doc/library/turtle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ Appearance
12791279
(direction of movement).
12801280

12811281
.. doctest::
1282-
:skipif: _tkinter is None
1282+
:skipif: _tkinter is None or 'always; deprecated method'
12831283

12841284
>>> turtle.reset()
12851285
>>> turtle.shape("circle")

Doc/whatsnew/3.2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,15 @@ aspects that are visible to the programmer:
322322
* The tag that is unique to each interpreter is accessible from the :mod:`imp`
323323
module:
324324

325-
>>> import imp
325+
>>> import imp # doctest: +SKIP
326326
>>> imp.get_tag() # doctest: +SKIP
327327
'cpython-32'
328328

329329
* Scripts that try to deduce source filename from the imported file now need to
330330
be smarter. It is no longer sufficient to simply strip the "c" from a ".pyc"
331331
filename. Instead, use the new functions in the :mod:`imp` module:
332332

333-
>>> imp.source_from_cache('c:/py32/lib/__pycache__/collections.cpython-32.pyc')
333+
>>> imp.source_from_cache('c:/py32/lib/__pycache__/collections.cpython-32.pyc') # doctest: +SKIP
334334
'c:/py32/lib/collections.py'
335335
>>> imp.cache_from_source('c:/py32/lib/collections.py') # doctest: +SKIP
336336
'c:/py32/lib/__pycache__/collections.cpython-32.pyc'

0 commit comments

Comments
 (0)