[TIP] Best way to do setup/teardown on a per-test basis using doctest?

Benji York benji at benjiyork.com
Mon Jul 2 07:09:57 PDT 2007

Michael Foord wrote:
> Python code in text files rather than in Python files is just as much a 
> drawback as having them in strings (in my opinion).

Source files look a lot like text files to me. <wink>  I use a syntax 
file that does full Python highlighting/handling in doctests, that helps 
quite a bit.

>>> and use lots of angle brackets!
>> I don't understand that remark.

> Because the tests have to resemble interactive sessions and require 
> lines start with '>>>' or '...'. At least that was my understanding. 
> ('>' being an angle bracket of course...)

Oh, I see now.  I was thinking about XML; I had no idea where you were 
going with that. :)

The "prompts, prompts everywhere" thing irritates me on occasion too, 
mostly when doing setup (usually in footnotes) that really is code and 
not test examples.

We've talked about adding an extension to doctest that lets you write 
code without prompts when you're not doing test examples but just want 
to execute the code.
Benji York

More information about the testing-in-python mailing list