Erotemic / xdoctest

A rewrite of Python's builtin doctest module (with pytest plugin integration) with AST instead of REGEX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add config for enabling rst

jayvdb opened this issue · comments

It would be helpful to have an easy way to include *.rst by default, without (ab)using addopts.

https://pypi.org/project/pytest-doctestplus/ provides this.

This is a reasonable request.

Do you mainly want to use it via the pytest runner, or would you want the native runner to support this as well?

My only interest is usage via pytest.

Looking into this I found that you can use --xdoctest-glob *.rst, but this causes the document to be parsed as a text file and as such only lines prefixed with >>> are parsed. I assume this isn't what you want to happen.

I think it would be good to define the desired behavior a bit more precisely, because right now I'm unsure.

Are we only looking to support blocks of code that look like this:

.. code-block:: python

    >>> import foo
    >>> foo.bar()

or would we want to run all code snippets? How should we deal with something like this?

.. code:: python


    def func1():
        """
        Example:
            >>> assert func1() == 1
        """
        return 1

that is no different to

>>> def func1():
>>>     """
>>>     Example:
>>>         >>> assert func1() == 1
>>>     """
>>>     return 1

doctest ignores nested doctest.
See PyCQA/pyflakes@6734c37 and PyCQA/pyflakes@93aa3c4 for some more unusual scenarios and indicating what doctest does/doesnt process.