[Tutor] redirecting testing output to file, using two different options

Alan Gauld alan.gauld at yahoo.co.uk
Wed May 16 13:30:57 EDT 2018


On 16/05/18 09:53, Yosef Levy wrote:
> Hello All,
> 
> I have testing environment.
> Code is written under Python 2.6.
> testing output should be redirected to log file.

You don't say which OS you are using but if it's a
Unix variant you could just use command line
redirection of stdout/stderr. That is probably
the simplest option and requires no code changes.

I think asserts and the logging module both
use stderr by default. At least I would hope that
they do!

Redirect stderr to a logfile with

$ python myscript.py arg1 arg2...argn 2> mylogfile.txt

Windows supports redirection too but I don't recall
how (or if) you can isolate stderr...

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list