[TIP] Doctest or unitest?

Jim Fulton jim at zope.com
Thu Mar 8 03:55:57 PST 2007


On Mar 7, 2007, at 9:21 AM, Michael Foord wrote:

> Isn't typing '...' all the time annoying ?

Yes.

> (or do you code first, test later... ? ;-)

Doctest was originally designed with this in mind.  We don't use it  
that way. We almost always test first and even when we don't, I  
rarely actually copy interactive sessions.

> Don't you also lose the help of the IDE with indentation and  
> autocomplete because you are no longer writing the tests in Python  
> files ?

For the most part.  There is a doctest mode for xemacs, but I've  
never gotten it working in my regular emacs.  It sounds like Benji  
has gotten something working for VIM.  Doctest is pretty popular in  
the Python world, so I expect that IDE support will come eventually,

No tool is perfect.  (I recently switched to a Mac for my laptop. I  
prefer it for that use, even though many aspects of the Mac UI annoy  
me far more than typing >>>s and ...s in doctests. :)

> We are writing an application (rather than a library), and so don't  
> *want* to document all of our internal classes / modules - so  
> documentation driven design has little to offer us for these tasks.  
> (and so the idea of using doctests becomes even weirder.)

But your "internal" libraries have users too: your developers.  IMO,  
documenting first makes interfaces better. Don't you want good  
internal interfaces too? Also I greatly appreciate documentation I  
wrote for APIs that I wrote and later forgot. :)

Jim

--
Jim Fulton			mailto:jim at zope.com		Python Powered!
CTO 				(540) 361-1714			http://www.python.org
Zope Corporation	http://www.zope.com		http://www.zope.org






More information about the testing-in-python mailing list