簡體   English   中英

鼻子測試正在捕獲我的打印語句的輸出。 如何規避這種情況?

[英]nosetests is capturing the output of my print statements. How to circumvent this?

當我打字

$ 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,必須有更好的方法。 請賜教。

任何一個:

$ nosetests --nocapture mytest.py

或者:

$ NOSE_NOCAPTURE=1 nosetests mytests.py

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

--nologcapture 

它對我有用

這是最近添加到鼻子而不是--nocapture這樣做:

nosetests -s

為了與http://travis-ci.org集成,我已將其放入.travis.yml

script:  "python setup.py nosetests -s"

其中setup.py包含:

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

嘗試這個,

nosetests -v 2 -s yourtest

標志期待秩序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM