简体   繁体   English

print语句在python proboscis中不起作用

[英]print statement is not working in python proboscis

We started writing our functional and unit test cases in python using nose framework. 我们开始使用nose框架在python中编写我们的功能和单元测试用例。 We started learning python while writing these tests. 我们在编写这些测试时开始学习python。 Since there are lot of dependencies between our test classes/functions, we decided to use proboscis framework on top of nose to control order of execution. 由于我们的测试类/函数之间存在很多依赖关系,我们决定在鼻子顶部使用长鼻框架来控制执行顺序。

We have quite a few 'print' statements in our tests and proboscis seems to be ignoring these! 在我们的测试中我们有很多'印刷'陈述,而长鼻似乎忽略了这些! Tests are running in expected order and testing them all but not printing our print statement data to console. 测试按预期顺序运行并测试它们,但不将打印语句数据打印到控制台。 Any idea what we are missing here? 知道我们在这里缺少什么吗?

BTW, we stopped deriving our classes from 'unittest.TestCase' once we moved to proboscis and decorated all classes and their member functions with @test. 顺便说一下,一旦我们转移到长鼻并用@test装饰所有类及其成员函数,我们就停止从'unittest.TestCase'派生我们的类。

Note : According to the Proboscis documentation "unused arguments get passed along to Nose or the unittest module" , so the following should apply to Proboscis by replacing nosetests with python run_tests.py . 注意 :根据Proboscis 文档 “未使用的参数传递给Nose或unittest模块” ,因此通过用python run_tests.py替换nosetests ,以下内容应适用于Proboscis

As @Wooble has mentioned in his comment, by default nose captures stdout and only displays it for failed tests. 正如@Wooble在他的评论中提到的那样,默认情况下, nose捕获stdout并仅显示失败的测试。 You can override this behaviour with the nosetests -s or --nocapture switch: 您可以使用nosetests -s--nocapture开关覆盖此行为:

$ nosetests --nocapture

Like @Wooble also mentions in his comment, I recommend using the logging module instead of print . 就像@Wooble在评论中提到的一样,我建议使用日志记录模块而不是print Then you only need to pass nosetests the -l DEBUG or --debug=DEBUG switch, where DEBUG is replaced by a comma separated list of the names of the loggers you want to display, to enable displaying of the logging output from your modules: 然后你只需要通过nosetests -l DEBUG--debug=DEBUG开关,其中DEBUG被一个逗号分隔的你想要显示的记录器名称列表替换,以便能够显示模块的日志输出:

$ nosetests --debug=your-logger-name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM