[TIP] Building a unittest.TestCase from a doctest

Titus Brown titus at caltech.edu
Tue Dec 18 23:34:17 PST 2007


On Tue, Dec 18, 2007 at 09:59:30PM -0800, Titus Brown wrote:
-> -> >My real goal is to get the tests to *run* under the aegis of a  
-> -> >different module;
-> -> 
-> -> I don't know what you mean by that.
-> 
-> Here is a functioning example (source files attached, or download from
-> 
-> 	http://iorich.caltech.edu/~t/transfer/doctest-ut.tar.gz
-> 
-> and run 'test.py', reproduced below):

I realized that I should motivate this a bit ;)

I have a somewhat complicated path setup for a library called 'motility'
[0], 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.

I don't think this is a situation complicated enough to warrant writing
a new plugin for nose, though; at least I'd rather not ;)

Any advice is welcome.

thanks,
--titus

[0] It's open source, of course, and available here:

	http://cartwheel.idyll.org/browser/trunk/motility/

Please don't comment on some of the C++ -- it's horrible.



More information about the testing-in-python mailing list