[Python-3000] doctests vs. unittests (was Re: pimp; restructuring the standard library)

Chris McDonough chrism at plope.com
Thu Jun 28 22:04:20 CEST 2007


On Jun 28, 2007, at 12:41 PM, Phillip J. Eby wrote:

> At 04:59 PM 6/28/2007 +0100, tav wrote:
>> * Abandoning of unit tests and replacing with full doctest  
>> coverage in
>> the style perfected by Jim Fulton and PJE. Integration with py.test.
>
> I believe that the origination credit for this rightly falls to Tim
> Peters.  (I just copied Jim, myself.)  Meanwhile, there are quite a
> few stdlib doctests now, and unittests still more than have their  
> place.
>
> Indeed, I'm also wary of breaking backward compatibility of unittest
> or doctest in Python 3.0, because that will make it even harder to
> port code over.  How will 2.x users run their existing test suites to
> verify their code has been ported correctly, if they can't keep using
> unittest?  As it is, they'll have to run them through 2to3, which
> AFAIK doesn't do doctests currently.

I've historically not been a huge fan of doctests because (these  
things may have changed since last I used doctest in anger):

a) If one of your fixture calls or an assertion fails for some  
reason, the rest of the test
    trips over itself trying to complete, usually without success  
because an invariant
    hasn't been met, and you need to scroll through a bunch of decoy  
output to
    see where the actual problem began.

b) I often use test bodies as convenient points to put a  
pdb.set_trace call if I want to
    debug something.  This wasn't very well supported when I was  
trying to use doctest.

As a result, I still use unittest pretty much exlusively to write  
tests.  I'd be sad if it went away.

- C



More information about the Python-3000 mailing list