Open
Description
Bug report
Initial PR and discussion: #111682
So, here's the problem:
Example 1::
>>> 1 + 2
3
Example 2:
.. doctest::
>>> 1 + 2
3
We have two tools: doctest
(builtin module) and sphinx
(3rd party) that can run these samples as doctests. The problem is that they define "doctest" term differently:
doctest
module says that both of these examples are doctestssphinx
says that only example with.. doctest::
directive is a doctest
This is problematic, because not all example are actually executed in CI, right now we have a CI job that uses Sphinx. So, in the result of this we have broken doctest (1st meaning) examples in the docs.
Examples:
- gh-54434: Make difflib.rst doctests pass. #111677
- gh-111181: Fix enum doctests #111180
- gh-111282: Fix NamedTemporaryFile example code #111283
What can we do?
Options:
- Add
.. doctest::
directives everywhere, but I think it is too much work and people will forget to do this - Try to use
doctest_test_doctest_blocks
, see docs https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html This is what I plan to do locally and I will send a PR with the results. I fear that quite a lot of doctests might be broken - Add doctests to
test_*
files using something like
def load_tests(loader, tests, pattern):
tests.addTests(doctest.DocFileSuite(
os.path.join(REPO_ROOT, 'Doc/library/LIBNAME.rst'),
module_relative=False,
))
return tests
The last option is also problematic, because right now we can only run doctests in CI, when PR only touches Doc/
folder, I am not sure that it will be easy with this setup.