problems redirecting unittest output to sys.stdout 
Author Message
 problems redirecting unittest output to sys.stdout

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. Until
now I started my tests like this :

if __name__ == '__main__':
    unittest.main()

To redirect the output I tried the following :

if __name__ == '__main__':
    import sys
    unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout))

This way the output is redirected to sys.stdout, but the command line
parameters are ignored. If I call my script with the '-v' parameter, I get
no verbose output. I have no idee where the parameters get lost !?

any idea ?

greetings
Achim



Wed, 13 Oct 2004 17:13:33 GMT  
 problems redirecting unittest output to sys.stdout
Achim Domma || Sat 27 Apr 2002 02:13:33a:

Quote:
> 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. Until now I started my tests like this :

> [..code..]

> This way the output is redirected to sys.stdout, but the command line
> parameters are ignored. If I call my script with the '-v' parameter, I
> get no verbose output. I have no idee where the parameters get lost !?

> any idea ?

This is one of the reasons i keep cygwin around. Link your windows
python binary something like /bin/wpy, and run 'wpy foo.py 2>&1 >
out.txt' or however you redirect streams under unix (haven't done it in
a while =).

There are also some free little 'bootstrap' kinda programs for windows,
which do something along the lines of '1. copy stderr to stdout, 2. run
whatever you pass to it as an argument' (like some slowdown programs).
This would be a significantly smaller way of getting what you want =)

--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



Wed, 13 Oct 2004 17:19:27 GMT  
 problems redirecting unittest output to sys.stdout

Quote:

> 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



Wed, 13 Oct 2004 17:44:29 GMT  
 problems redirecting unittest output to sys.stdout

Quote:

> > 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.

yes, 2> works fine ! Thanks !

Achim



Wed, 13 Oct 2004 18:26:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Redirecting the output from sys.stdout

2. redirecting sys.stdout to a Tkinter Text widget?

3. redirecting sys.stdout and threads

4. redirect sys.stdout to C++ ?

5. Binary output on sys.stdout

6. Printing binary output on sys.stdout under Windows

7. Redirecting stdout to stdout and file , how ?

8. Problem getting stdout redirected for embedded Python

9. redirect stdout problem

10. problems redirecting python output

11. Windows python 2.2.1 IDLE glitch - unittest output display nothing

12. Redirecting STDOUT

 

 
Powered by phpBB® Forum Software