虽然我知道这可以从命令行完成nosetests --nocapture test.py
我想知道是否可以添加代码test.py
,这样我就可以在nosetests test.py
不添加--nosecapture
.
您可以通过将-s
标志添加到终端命令来查看打印语句。例如
$ nosetests -s test.py
-s, --nocapture
不要捕获标准输出(将立即打印任何标准输出)[NOSE_NOCAPTURE]。
在这里查看官方文档
You can do it by either defining environment NOSE_NOCAPTURE
variable, creating .noserc
or nose.cfg
file in your home directory that will have something like:
[nosetests]
nocapture=1
or by passing arguments to nose directly in python when calling nose.run()
as described in nose documentation