Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include doctests from files #9659

Open
HaoZeke opened this issue Sep 20, 2021 · 1 comment
Open

Include doctests from files #9659

HaoZeke opened this issue Sep 20, 2021 · 1 comment
Labels
type:enhancement enhance or introduce a new feature

Comments

@HaoZeke
Copy link

HaoZeke commented Sep 20, 2021

Is your feature request related to a problem? Please describe.
I've been working with .. doctest:: for a while now and some snippets are a little too long to be comfortably put in the documentation.

Naturally there are unit tests but sometimes (mostly for demonstrating benchmarks) it is desirable to have a class or something defined over multiple lines with sensitive indentation be part of the doctest.

Currently this means carefully editing it in a .py file and then putting it in the rst.

Describe the solution you'd like
Allow .. include:: to work with .. doctest::

Describe alternatives you've considered
Doug Hellmann has a rather involved alternative using cog discussed here but I'd rather not go that far.

Additional context
The motivating context is this NumPy document which had an indent bug preventing us from doctests.

@HaoZeke HaoZeke added the type:enhancement enhance or introduce a new feature label Sep 20, 2021
@tk0miya
Copy link
Member

tk0miya commented Sep 26, 2021

Sphinx does not prevent the including doctest from external file. How about this?

# index.rst

.. include:: example.doctest
# example.doctest
>>> print(1)
1

@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

3 participants