Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9558d22

Browse filesBrowse files
donBarbospicnixz
andauthored
gh-130160: use .. program:: directive for documenting doctest CLI (#131034)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 563ab5c commit 9558d22
Copy full SHA for 9558d22

File tree

2 files changed

+47
-25
lines changed
Filter options

2 files changed

+47
-25
lines changed

‎Doc/library/cmdline.rst

Copy file name to clipboardExpand all lines: Doc/library/cmdline.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The following modules have a command-line interface.
1212
* :ref:`compileall <compileall-cli>`
1313
* :mod:`cProfile`: see :ref:`profile <profile-cli>`
1414
* :ref:`dis <dis-cli>`
15-
* :mod:`doctest`
15+
* :ref:`doctest <doctest-cli>`
1616
* :mod:`!encodings.rot_13`
1717
* :mod:`ensurepip`
1818
* :mod:`filecmp`

‎Doc/library/doctest.rst

Copy file name to clipboardExpand all lines: Doc/library/doctest.rst
+46-24Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,8 @@ prohibit it by passing ``verbose=False``. In either of those cases,
177177
``sys.argv`` is not examined by :func:`testmod` (so passing ``-v`` or not
178178
has no effect).
179179

180-
There is also a command line shortcut for running :func:`testmod`. You can
181-
instruct the Python interpreter to run the doctest module directly from the
182-
standard library and pass the module name(s) on the command line::
183-
184-
python -m doctest -v example.py
185-
186-
This will import :file:`example.py` as a standalone module and run
187-
:func:`testmod` on it. Note that this may not work correctly if the file is
188-
part of a package and imports other submodules from that package.
180+
There is also a command line shortcut for running :func:`testmod`, see section
181+
:ref:`doctest-cli`.
189182

190183
For more information on :func:`testmod`, see section :ref:`doctest-basic-api`.
191184

@@ -248,16 +241,53 @@ Like :func:`testmod`, :func:`testfile`'s verbosity can be set with the
248241
``-v`` command-line switch or with the optional keyword argument
249242
*verbose*.
250243

251-
There is also a command line shortcut for running :func:`testfile`. You can
252-
instruct the Python interpreter to run the doctest module directly from the
253-
standard library and pass the file name(s) on the command line::
244+
There is also a command line shortcut for running :func:`testfile`, see section
245+
:ref:`doctest-cli`.
254246

255-
python -m doctest -v example.txt
247+
For more information on :func:`testfile`, see section :ref:`doctest-basic-api`.
256248

257-
Because the file name does not end with :file:`.py`, :mod:`doctest` infers that
258-
it must be run with :func:`testfile`, not :func:`testmod`.
259249

260-
For more information on :func:`testfile`, see section :ref:`doctest-basic-api`.
250+
.. _doctest-cli:
251+
252+
Command-line Usage
253+
------------------
254+
255+
The :mod:`doctest` module can be invoked as a script from the command line:
256+
257+
.. code-block:: bash
258+
259+
python -m doctest [-v] [-o OPTION] [-f] file [file ...]
260+
261+
.. program:: doctest
262+
263+
.. option:: -v, --verbose
264+
265+
Detailed report of all examples tried is printed to standard output,
266+
along with assorted summaries at the end::
267+
268+
python -m doctest -v example.py
269+
270+
This will import :file:`example.py` as a standalone module and run
271+
:func:`testmod` on it. Note that this may not work correctly if the
272+
file is part of a package and imports other submodules from that package.
273+
274+
If the file name does not end with :file:`.py`, :mod:`!doctest` infers
275+
that it must be run with :func:`testfile` instead::
276+
277+
python -m doctest -v example.txt
278+
279+
.. option:: -o, --option <option>
280+
281+
Option flags control various aspects of doctest's behavior, see section
282+
:ref:`doctest-options`.
283+
284+
.. versionadded:: 3.4
285+
286+
.. option:: -f, --fail-fast
287+
288+
This is shorthand for ``-o FAIL_FAST``.
289+
290+
.. versionadded:: 3.4
261291

262292

263293
.. _doctest-how-it-works:
@@ -540,9 +570,6 @@ Symbolic names for the flags are supplied as module constants, which can be
540570
The names can also be used in :ref:`doctest directives <doctest-directives>`,
541571
and may be passed to the doctest command line interface via the ``-o`` option.
542572

543-
.. versionadded:: 3.4
544-
The ``-o`` command line option.
545-
546573
The first group of options define test semantics, controlling aspects of how
547574
doctest decides whether actual output matches an example's expected output:
548575

@@ -682,11 +709,6 @@ The second group of options controls how test failures are reported:
682709
1. This flag may be useful during debugging, since examples after the first
683710
failure won't even produce debugging output.
684711

685-
The doctest command line accepts the option ``-f`` as a shorthand for ``-o
686-
FAIL_FAST``.
687-
688-
.. versionadded:: 3.4
689-
690712

691713
.. data:: REPORTING_FLAGS
692714

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.