Skip to content

Decide what should we do with doctests in CI #111704

Description

@sobolevn

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 doctests
  • sphinx 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:

What can we do?

Options:

  1. Add .. doctest:: directives everywhere, but I think it is too much work and people will forget to do this
  2. 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
  3. 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.

CC @AlexWaygood @AA-Turner

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buildThe build process and cross-builddocsDocumentation in the Doc dirtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions