如何在运行单元测试时抑制 App Engine 日志记录?
我在我的 GAE 应用程序中使用 gaetestbed,它运行得很好。但是,当您的测试不正确时 nose 打印的有用语句会被 App Engine 的日志记录冲走:
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 85, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 87, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 86, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 87, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 28 tests in 3.605s
有没有办法抑制这种情况,以便我可以获得干净的 something != some else仅错误消息?
I'm using gaetestbed in my GAE app, and it's working very well. However, the useful statements that nose prints when your test is incorrect is being washed away by App Engine's logging:
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 85, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 87, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 86, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
root: Level 9: Evaling filter expression "datastore_types.Key.from_path(u'User', 87, _app=u'tipfy') == datastore_types.Key.from_path(u'User', 87, _app=u'tipfy')"
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 28 tests in 3.605s
Is there a way to suppress this so I can get the clean something != something else
error messages only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否适用于 gaetestbed,但使用 django-nose 我可以将以下内容添加到我的 settings.py 中:
另一个解决方法是仅反向 grep 输出:
Not sure that this will work in gaetestbed, but using django-nose I can add the following to my settings.py:
Another work-around is to just inverse grep the output:
这里有一个笨方法,
在你的nose/plugins/中找到capture.py和logcapture.py,
在这两个文件中找到函数
addCaptureToErr
,然后修改它。(我不知道哪一个是正确的,请自行测试)
原始代码应该如下所示:
将其更改为
应该可以工作。
Here is a stupid way,
find capture.py and logcapture.py in your nose/plugins/
find function
addCaptureToErr
in both files, then revise it.(I don't know which one is the right one, please test yourself)
original code should look like this:
change it into
It should works.
我还没有尝试过 Bigbear 的建议,但我确实找到了解决该问题的快速解决方法:将 err 输出通过管道传输到文件中。
这使您可以在顶部看到错误的清晰打印输出 。文件,以及其下方 App Engine 日志记录的最小化输出。
I haven't tried Bigbear's suggestion, but I did find a quick workaround to the problem: pipe the err output into a file.
This allows you to see a clean printout of your errors at the top of the file, and a minimized output of App Engine logging beneath it.