[TIP] Building a unittest.TestCase from a doctest
titus at caltech.edu
Wed Dec 19 00:12:51 PST 2007
On Tue, Dec 18, 2007 at 11:34:17PM -0800, Titus Brown wrote:
-> I have a somewhat complicated path setup for a library called 'motility'
-> , which looks for fuzzy matches to known patterns in DNA. It
-> contains Python bindings to a C++ library.
-> Recently I wrote a doctest-style tutorial for motility, and I also
-> started using doctests for function docs. These are scattered
-> throughout the library:
-> tests/ - contains nose-style unit tests
-> doc/ - some files contain doctests
-> python/motility/*.py - some files contain doctests
-> I would like to use nose to run all of the doctests and include the
-> output in the general test results, but I cannot figure out a good
-> (clean, simple) way of including the doctests in the tests/ directory.
-> One way would be to add a file in the tests/ directory that loaded all
-> of the doctests and executed them, but I can't figure out how to get
-> them to be included as a simple TestCase.
Here's my current solution:
It's not perfect, because each batch of doctests is represented as a
*single* test, but it works. It also lets me run all the doctests with
a single shell command, too.
More information about the testing-in-python