twmr / pytest-sphinx

sphinx doctest plugin for pytest
BSD 3-Clause "New" or "Revised" License
29 stars 6 forks source link

Support for `.md` / `myst-parser` #30

Open tony opened 2 years ago

tony commented 2 years ago

myst-parser (github) supports sphinx roles.

Quick links:

Normal directive syntax:

```{doctest}

>>> print(1 + 2)
3

[`eval-rst`](https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html#roles-directives:~:text=For%20special%20cases%2C%20MySt%20also%20offers%20the%20eval%2Drst%20directive.%20This%20will%20parse%20the%20content%20as%20ReStructuredText%3A) directive:

````markdown
```{eval-rst}

.. doctest::

   >>> print(1 + 2)
   3
twmr commented 2 years ago

Sounds like a good idea! Thx for the suggestion! I think it makes sense to use the MyST parser for extracting the doctests. Are you familiar with the MyST python api?

tony commented 2 years ago

@thisch Not enough to champion a PR

The reference page should be a good place to start:

tony commented 2 years ago

My ambition would be to use it here: https://libvcs.git-pull.com/parse/git.html (.md, .py)

Right now I have doctest everywhere as its amazingly efficient to have meaningful tests that double as documentation, but I'd like to have tutorials, how to, and explanations where the examples are backed by tests.

Workaround: If using automodule directives, write the doctests at the top of the .py file.