When using Sphinx and autodoc to document a Python project, you can use :Example:
to include a code sample in your module/class/function docstring, which Sphinx will kindly syntax highlight for you. Something like so.
>>> rng = Range(0, 1000)
>>> rng
[0, 1000)
>>> len(rng)
1000
>>> rng.start = 500
>>> rng.start
500
>>> rng.end
1000
>>>
I copied and pasted this from the Python interpreter. Is there any way to have Sphinx or autodoc execute the code and capture the output automatically for the documentation?
My main concern is copy-and-pasted code/output getting out-of-sync with the actual current code behavior.
The standard library includes
doctest
, which can identify, execute and verify interactive examples from text files or docstrings.