Skip to content

Remove doctest directives from example blocks #899

Description

@Neraste

Problem Description

Example blocs inside docstrings can be tested to check they don’t contain mistakes, such special tests are named doctests. Python allows doctests to contain options, passed as directives, to modify the evaluation of the test. By instance:

>>> print(list(range(20)))  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[0,    1, ...,   18,    19]

where +ELLIPSIS enables ... to be used as a regex .*, and +NORMALIZE_WHITESPACE makes spaces not accounted for in the evaluation.

Directives are convenient for writing doctests, but are not useful in a documentation.

Proposal

I suggest to filter doctest directives out in the outputed HTML document. Given that directives are always formated as # doctest: <something>, I think it would be fairly easy to identify them with a regex. This behavior could be modified by a pdoc option, such as --keep-doctests-directives.

What do you think?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions