简体   繁体   English

如何将nosetests的输出重定向到文本文件?

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

I've tried "nosetests p1.py > text.txt" and it is not working. 我尝试过“nosetests p1.py> text.txt”并且它无法正常工作。

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. 最后 - 显然 - 提示:如果您不在测试文件目录中,请在.py文件之前添加。

I want to add more detail here. 我想在这里添加更多细节。

On my version (v1.3.7) Nose is logging on stderr instead of the expected stdout . 在我的版本(v1.3.7)上,Nose正在登录stderr而不是预期的stdout Why nose logs on stderr instead of stdout is beyond me. 为什么鼻子登录stderr而不是stdout超出我的范围。 So the solution is to redirect the stderr stream to your file. 因此,解决方案是将stderr流重定向到您的文件。 The redirect character sends stdout by default. 重定向字符默认发送stdout The --nocapture, -s flag is used to stop nose from capturing your own print statements. --nocapture, -s标志用于阻止鼻子捕获您自己的print语句。

$ 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. 有一点需要注意,就是虽然stderr ,似乎在每个输出端被刷新, stdout没有得到刷新,所以如果你是tail荷兰国际集团的stdout.log文件,你不会看到输出,直到鼻子或OS决定冲洗。 So if you think it's not working try exiting the test runner which will cause stdout to flush. 因此,如果您认为它不起作用,请尝试退出测试运行器,这将导致stdout刷新。

See this answer on redirecting linux streams . 有关重定向linux流的信息,请参阅此答案。

参数-s - 不捕获标准输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM