[Python-ideas] Fwd: doctest

Ethan Furman ethan at stoneleaf.us
Mon Feb 27 20:58:52 CET 2012

Mark Janssen wrote:
> On Fri, Feb 17, 2012 at 3:12 PM, Nick Coghlan wrote:
>> On Sat, Feb 18, 2012 at 7:57 AM, Mark Janssen wrote:
>>> Anyway... of course patches welcome, yes...  ;^)
>> Not really. doctest is for *testing code example in docs*.
> I understand.  This is exactly what I was wanting to use it for.  As
> Tim says "literate testing" or "executable documentation".
> The suggestions I made are for enhancing those two.
> Personally, I don't find unittest very suitable for test-driven
> *development*, although it *is* obviously well-suited for writing
> assurance tests otherwise.

I like unittest for TDD.

> The key difference, to me, is in that doctest promotes tests being
> written in order to have the *additional functionality* of
> documentation.    That makes it fun since your getting "twice the
> value for the cost of one", and that alone is the major item which
> drives test-driven development (IMHO) within the spirit of python,
> otherwise unittest is rather bulky to write in and of itself.

unittest can be a bit bulky, but definitely worth it IMO, especially 
when covering the corner cases.

I have not used doctest, but I can say that I strongly dislike having 
more than one or two examples in a docstring.  Having all possibilities 
(including corner cases) in a separate file I am okay with (as that 
would be documentation -- when I'm reading code I want to see code, and 
I'll look up the docs if I have a question).

The other gripe I have (possibly easily fixed): my python prompt is 
'-->' (makes email posting easier) -- should my doctests still use 
'>>>'?  Will doctest fail on my machine?

> Does anyone really use unittest outside the context of shop policy?


More information about the Python-ideas mailing list