148

当我输入

$ nosetests -v mytest.py

当所有测试通过时,我所有的打印输出都会被捕获。即使一切都通过了,我也想看到打印输出。

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

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)

感觉很hackish,必须有更好的方法。请启发我。

4

5 回答 5

223

任何一个:

$ nosetests --nocapture mytest.py

或者:

$ NOSE_NOCAPTURE=1 nosetests mytests.py

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

于 2011-05-12T08:49:49.613 回答
17

采用

--nologcapture 

它对我有用

于 2013-09-24T09:30:37.163 回答
10

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

nosetests -s
于 2015-02-11T15:51:26.257 回答
3

为了与http://travis-ci.org集成,我将其放入.travis.yml

script:  "python setup.py nosetests -s"

其中setup.py包含:

setup(
    ...
    tests_require=['nose>=1.0'],
    test_suite='nose.collector',
)
于 2014-08-06T13:15:00.277 回答
1

试试这个,

nosetests -v 2 -s yourtest

标志期望秩序。

于 2021-03-11T09:26:15.490 回答