From 01be5881a938c3912708cff80d638eefea94a57c Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sun, 16 Mar 2025 15:53:22 +0400 Subject: [PATCH] gh-130160: use `.. program::` directive for documenting `doctest` CLI (GH-131034) (cherry picked from commit 9558d22ac308c102e4f843541eead2022050225e) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: donBarbos Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/cmdline.rst | 2 +- Doc/library/doctest.rst | 70 +++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Doc/library/cmdline.rst b/Doc/library/cmdline.rst index 487fd775337af3..d10ff594ecb1f1 100644 --- a/Doc/library/cmdline.rst +++ b/Doc/library/cmdline.rst @@ -13,7 +13,7 @@ The following modules have a command-line interface. * :mod:`cProfile`: see :ref:`profile ` * :ref:`difflib ` * :ref:`dis ` -* :mod:`doctest` +* :ref:`doctest ` * :mod:`!encodings.rot_13` * :mod:`ensurepip` * :mod:`filecmp` diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 6b0282eed49566..a968d5d9192608 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -173,15 +173,8 @@ prohibit it by passing ``verbose=False``. In either of those cases, ``sys.argv`` is not examined by :func:`testmod` (so passing ``-v`` or not has no effect). -There is also a command line shortcut for running :func:`testmod`. You can -instruct the Python interpreter to run the doctest module directly from the -standard library and pass the module name(s) on the command line:: - - python -m doctest -v example.py - -This will import :file:`example.py` as a standalone module and run -:func:`testmod` on it. Note that this may not work correctly if the file is -part of a package and imports other submodules from that package. +There is also a command line shortcut for running :func:`testmod`, see section +:ref:`doctest-cli`. For more information on :func:`testmod`, see section :ref:`doctest-basic-api`. @@ -244,16 +237,53 @@ Like :func:`testmod`, :func:`testfile`'s verbosity can be set with the ``-v`` command-line switch or with the optional keyword argument *verbose*. -There is also a command line shortcut for running :func:`testfile`. You can -instruct the Python interpreter to run the doctest module directly from the -standard library and pass the file name(s) on the command line:: +There is also a command line shortcut for running :func:`testfile`, see section +:ref:`doctest-cli`. - python -m doctest -v example.txt +For more information on :func:`testfile`, see section :ref:`doctest-basic-api`. -Because the file name does not end with :file:`.py`, :mod:`doctest` infers that -it must be run with :func:`testfile`, not :func:`testmod`. -For more information on :func:`testfile`, see section :ref:`doctest-basic-api`. +.. _doctest-cli: + +Command-line Usage +------------------ + +The :mod:`doctest` module can be invoked as a script from the command line: + +.. code-block:: bash + + python -m doctest [-v] [-o OPTION] [-f] file [file ...] + +.. program:: doctest + +.. option:: -v, --verbose + + Detailed report of all examples tried is printed to standard output, + along with assorted summaries at the end:: + + python -m doctest -v example.py + + This will import :file:`example.py` as a standalone module and run + :func:`testmod` on it. Note that this may not work correctly if the + file is part of a package and imports other submodules from that package. + + If the file name does not end with :file:`.py`, :mod:`!doctest` infers + that it must be run with :func:`testfile` instead:: + + python -m doctest -v example.txt + +.. option:: -o, --option