How Do I Create Doc Tests?

Created by Tim Cook
Keywords:
doctests
Last updated by:
Eduardo Ribeiro

Install the developer branch of OSHIP, described in https://answers.launchpad.net/oship/+faq/392. Now start the server in debug mode with bin/oship-debug

You will then have access to the complete OSHIP environment including the ZODB at a Python prompt.
Next you will need to import the module that you will be creating tests on.

Now simply create instances of the classes that you want to test. Edge cases, failures, etc. Copy this output from your terminal into the class docstring and it will be detected as a doctest by the testing framework.

You now will simply copy the python prompt with the tests you made in a text file in the directory ./tests/[somefile].txt, with [somefile] being the class that you are testing on.

You can see some .py file in the tests directory. Those files were part of an aproach that used a complete test substructure unit, but with grok, that process now is much simplified and we are not using those files for the time being.

You can see more information on http://grok.zope.org/doc/current/reference/testing.html#grok.testing.register_all_tests for more information on setting up the grok based testing framework.