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 .
参数-s
- 不捕获标准输出
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.