I've tried "nosetests p1.py > text.txt" and it is not working.
What is the proper way to pipe this console output?
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.
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 tail
ing 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With