problems redirecting unittest output to sys.stdout

Alex Martelli aleax at aleax.it
Sat Apr 27 05:44:29 EDT 2002


Achim Domma wrote:

> Hi,
> 
> I want to redirect the output of a unittest to a textfile (on Windows).
> The default stream is sys.stderr which can not be redirected on windows.

Of course it can be -- depends on what Windows version you have.  With
NT's CMD.EXE (thus I believe also /2000 and /XP), 2>blah on the command
line works fine.  The 4NT shell works for Win/95 and up and supports
stderr redirection.  
http://www.developersdomain.com/vb/articles/redirectpipe.htm shows
how to to it in VB and C and includes links.
ftp://ftp.externet.hu/pub/mirror/sac/utilmisc/errout.zip is one of
a zillion utilities doing the same.

But of course it's even easier in Python -- just ensure you execute

import sys
sys.stderr = open('wop', 'w')

or

sys.stderr = sys.stdout

or whatever, before you import unittest.



Alex




More information about the Python-list mailing list