开发者

How do I get Sphinx to test code embedded in documentation?

开发者 https://www.devze.com 2022-12-16 04:38 出处:网络
If this code is a blockquote in m开发者_Python百科y documentation, what do I need to do to make Sphinx run it when the documentation is generated? I tried adding

If this code is a blockquote in m开发者_Python百科y 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 .rst sources and the Sphinx doctest extension to conf.py, but I got an error complaining about unexpected indentation on the first line of the function body. Is Sphinx's doctest able to run functions defined in the documentation?


The testcode directive needs a matching testoutput directive.

Here's the example from the documentation.

.. testcode::

   print 'Output     text.'

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

   Output text.
0

精彩评论

暂无评论...
验证码 换一张
取 消