nosetests捕获我的print语句的输出.如何规避这个?

Fra*_*ery 142 python nosetests

当我输入

$ nosetests -v mytest.py
Run Code Online (Sandbox Code Playgroud)

所有测试通过后,我的所有打印输出都被捕获.我想看看打印输出甚至一切都过去了.

所以我正在做的是强制断言错误来查看输出,就像这样.

class MyTest(TestCase):

    def setUp(self):
        self.debug = False

    def test_0(self):
        a = .... # construct an instance of something
        # ... some tests statements
        print a.dump()
        if self.debug:
            eq_(0,1)
Run Code Online (Sandbox Code Playgroud)

感觉如此hackish,必须有一个更好的方式.请赐教.

cod*_*ape 216

或者:

$ nosetests --nocapture mytest.py
Run Code Online (Sandbox Code Playgroud)

要么:

$ NOSE_NOCAPTURE=1 nosetests mytests.py
Run Code Online (Sandbox Code Playgroud)

(也可以在nose.cfg文件中指定,参见nosetests --help)

  • 这个命令的简短版本是`nosetests -s`.对于其他标准选项,请参阅`-h`帮助或[基本用法](https://nose.readthedocs.org/en/latest/usage.html#selecting-tests)帮助页面. (12认同)
  • 谢谢你的有用答案.我还发现知道我可以将这个参数传递给nose.main(),如帖子所述:http://stackoverflow.com/questions/7070501/passing-options-to-nose-in-a-python-测试脚本 (3认同)
  • 如果有人想查看源代码:http://nose.readthedocs.org/en/latest/plugins/capture.html (2认同)
  • 对我不起作用,即使使用此选项,当测试通过时我的打印语句也不会打印 (2认同)

Dam*_*ian 16

使用

--nologcapture 
Run Code Online (Sandbox Code Playgroud)

它对我有用


moe*_*dol 9

最近添加到鼻子而不是--nocapture这样做:

nosetests -s

  • @BhargavRao"做这个鼻子测试-s"回答了这个问题(虽然没有最少考虑语法).我不确定你为什么反对. (7认同)
  • 请注意,“-s”是“--nocapture”标志的单字母缩写,如[根据文档](https://nose.readthedocs.io/en/latest/plugins/capture.html)。 (2认同)