Questions tagged «python-nose»

11
如何在python中使用鼻子测试/单元测试来断言输出?
我正在为下一个功能编写测试: def foo(): print 'hello world!' 因此,当我要测试此功能时,代码将如下所示: import sys from foomodule import foo def test_foo(): foo() output = sys.stdout.getline().strip() # because stdout is an StringIO instance assert output == 'hello world!' 但是,如果我使用-s参数运行鼻子测试,则测试将崩溃。如何使用unittest或鼻子模块捕获输出?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.