Skip to content

doctest: Need a way to locally disable the trimming of doctest flags #6698

@JulienPalard

Description

@JulienPalard

Is your feature request related to a problem? Please describe.

In cpython, we have the doctest documentation, in this we're having for example:

This test also passes, and also requires a directive to do
so::

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

So in this specific case, we need the "# doctest: +ELLIPSIS" to still be visible in the generated documents, because it's part of what's we're documenting.

Describe the solution you'd like
I'd like to be able to locally disable the stripping by something like:

.. doctest::
   :trim_flags: False

   >>> print(list(range(20))) # doctest: +NORMALIZE_WHITESPACE
   [0,   1,  2,  3,  4,  5,  6,  7,  8,  9,
   10,  11, 12, 13, 14, 15, 16, 17, 18, 19]

Describe alternatives you've considered
In cpython we were messing with self.highlighter.trim_doctest_flags, which is now deprecated. trim_doctest_flags still exists but as a global option, so it's harder to trick it to act on a single code block with not too much ugly tricks.

Additional context
https://bugs.python.org/issue36675

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions