Doctest and unittest are like 2 extremes of testing your python code. One is simple and intuitive and the other is powerful and requires more formality. In Python 2.4, doctest, builds in some of the power of unittest, perhaps bridging the gap between the two. This example shows you how to use doctest and the doctest.DocFileSuite feature.
Python, 44 lines
Doctest is a way to use docstring examples (that look like interactive intrepreter sessions) as a way to check your code. Docstrings (text you put at the beginning of a files, functions, and classes) are a simple way of documenting your code and is also leveraged by pydoc and help. It is a good feature in python and adding testing capability to it just makes it even better. Doctest keep examples alive. A potential problem with doctest is that you may have so many tests that your docstrings would hinder rather than help understanding of your code.
Python's unittest is a more formal framework for testing. You put your tests in a separate file and generally inherit from unittest.TestCase to build your own testing class. If you have lots of testcases you can put them together in a suite.
In python 2.4, doctest takes advantage of unittest. You can move your doctests into a separate file with doctest.DocFileSuite -- avoiding the problems of clutter with doctest. The DocFileSuite function adds all of your doctests as unittest testcase to a unittest suite. This hybrid lets you take advantage of the best of both worlds.