[Tutor] testing: doctest and unittest

Alex Hunsley lard at tardis.ed.ac.uk
Wed Nov 9 00:50:06 CET 2005


Colin J. Williams wrote:

> Alex Hunsley wrote:
>
>> Regards testing, I've been playing with both the unittest 
>> (http://pyunit.sourceforge.net/pyunit.html) and doctest 
>> (http://docs.python.org/lib/module-doctest.html). I was wondering 
>> what peoples thoughts were on the effectiveness and convenience of 
>> one versus the other. It seems to me that doctest is good for quicky 
>> and straightforwards input/output tests for small units, whereas 
>> unittest would be good for dynamic or complicated testing.
>>
>> Where do you seasoned pythonites see unittest and doctest in relation 
>> to each other? Do you only use one or the other?
>>
>> ta,
>> alex
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>  
>>
> I looked at doctest and feel that it clutters the module text and so 
> would prefer unittest but I haven't yet got to formalizing my tests in 
> that way.
>
> See some of the numarray source as an example of clutter.  Some argue 
> that having the examples in the source is beneficial.  I agree but 
> feel that the clutter outweighs the benefit.

I also feel that the clutter aspect of doctest can be a little bit of a 
put off. I like the idea of the having the target code nicely seperate 
from the tests, and really thorough doctests could swamp the target code 
a little too much!
Plus, of course, if you write unittests, there are more options 
apparently available,  like using the graphical test runner, etc. 
doctest is simpler (not always necessarily a bad thing).

ta
alex




More information about the Tutor mailing list