鼻子测试正在捕获我的打印语句的输出。如何规避呢?

问题:鼻子测试正在捕获我的打印语句的输出。如何规避呢?

当我打字

$ 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)

感觉很难受,必须有更好的方法。请赐教。

When I type

$ nosetests -v mytest.py

all my print outputs are captured when all tests pass. I want to see print outputs even everything passes.

So what I’m doing is to force an assertion error to see the output, like this.

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)

It feels so hackish, there must be a better way. Enlighten me please.


回答 0

要么:

$ nosetests --nocapture mytest.py

要么:

$ NOSE_NOCAPTURE=1 nosetests mytests.py

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

Either:

$ nosetests --nocapture mytest.py

Or:

$ NOSE_NOCAPTURE=1 nosetests mytests.py

(it can also be specified in the nose.cfg file, see nosetests --help)


回答 1

--nologcapture 

它对我有用

Use

--nologcapture 

it worked for me


回答 2

这是最近添加到鼻子的,而不是–nocapture做的:

鼻子测试

This was added recently to nose instead of –nocapture do this:

nosetests -s


回答 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',
)

In order to integrate with http://travis-ci.org I have put this into .travis.yml:

script:  "python setup.py nosetests -s"

where setup.py contains:

setup(
    ...
    tests_require=['nose>=1.0'],
    test_suite='nose.collector',
)