Skip to content

Instantly share code, notes, and snippets.

@moreati
Last active October 14, 2015 16:27
Show Gist options
  • Save moreati/57704808c473b6ad1d25 to your computer and use it in GitHub Desktop.
Save moreati/57704808c473b6ad1d25 to your computer and use it in GitHub Desktop.
How to have hidden setup code for doctests

This code is executed, but not rendered

This code is both executed by doctest and rendered in the output document

>>> datetime.datetime.fromtimestamp(0)
datetime.datetime(1970, 1, 1, 1, 0)
$ python -m doctest -v example.rst
Trying:
import datetime
Expecting nothing
ok
Trying:
datetime.datetime.fromtimestamp(0)
Expecting:
datetime.datetime(1970, 1, 1, 1, 0)
ok
1 items passed all tests:
2 tests in fred.rst
2 tests in 1 items.
2 passed and 0 failed.
Test passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment