Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i redirect the output of nosetests to a textfile?

I've tried "nosetests p1.py > text.txt" and it is not working.

What is the proper way to pipe this console output?

like image 870
iCodeLikeImDrunk Avatar asked Mar 01 '12 16:03

iCodeLikeImDrunk


2 Answers

Try:

nosetests -s p1.py > text.txt 2>&1

Last --obvious--tip: If you are not in the test file directory, add before the .py file.

like image 193
turtlebender Avatar answered Oct 12 '22 23:10

turtlebender


I want to add more detail here.

On my version (v1.3.7) Nose is logging on stderr instead of the expected stdout. Why nose logs on stderr instead of stdout is beyond me. So the solution is to redirect the stderr stream to your file. The redirect character sends stdout by default. The --nocapture, -s flag is used to stop nose from capturing your own print statements.

$ nosetests -s -v test/ > stdout.log 2> stderr.log

One thing to note, is although stderr seems to be flushed on each output, stdout does not get flushed, so if you are tailing the stdout.log file, you will not see output until nose or the OS decides to flush. So if you think it's not working try exiting the test runner which will cause stdout to flush.

See this answer on redirecting linux streams.

like image 33
James Avatar answered Oct 13 '22 00:10

James