How to force Sphinx to check the code embedded in the documentation?

If this code is a block comment in my documentation, what do I need to do to make Sphinx run it when the documentation is generated? I tried adding

.. testcode::

    import datetime
    def today():
        return datetime.datetime.now().date()
    if True:
        today()

to one of the sources .rstand the extension of the doctrine of Sphinx to conf.py, but I got an error complaining about an unexpected indent in the first line of the function body. Are Sphinx doctrines capable of performing the functions defined in the documentation?

+3
source share
1 answer

The directive testcodeneeds an appropriate directive testoutput.

Here is an example from the documentation.

.. testcode::

   print 'Output     text.'

.. testoutput::
   :hide:
   :options: -ELLIPSIS, +NORMALIZE_WHITESPACE

   Output text.
+3
source

Source: https://habr.com/ru/post/1727646/


All Articles