18

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

What is the proper way to pipe this console output?

iCodeLikeImDrunk
  • 17,085
  • 35
  • 108
  • 169

3 Answers3

25

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.

thesayhey
  • 938
  • 3
  • 17
  • 38
turtlebender
  • 1,907
  • 15
  • 16
2

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.

James
  • 2,488
  • 2
  • 28
  • 45
1

parameter -s - Not capturing stdout

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42