Testing & stdout

Peter Hansen peter at engcorp.com
Tue Nov 4 14:29:21 CET 2003


Miki Tebeka wrote:
> 
> In my test suite I also test some function that output messages to stdout.
> Is there an easy way to temporary divert stdout to another location?
> 
> Currently I'm using:
[snip]
> This works fine if no one is caching stdout somewhere.

"Caching stdout"?  What's that mean?  Who would do such a thing?

Normally issues like this would have an answer "use flush()", but with
the example you gave, where you're diverting output directly to a StringIO,
I can't see how that would help.  I also can't see why it would be needed.

If you have code which is actually holding back output which it will
eventually write to stdout (is that what "caching stdout" means here?)
then obviously diverting stdout to a StringIO is going to do nothing
useful for you in your unit tests.

I think you need to explain more or something... sorry.

-Peter




More information about the Python-list mailing list