如何在运行单元测试时抑制 App Engine 日志记录?

发布于 2024-10-06 16:45:31 字数 1048 浏览 0 评论 0原文

我在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

邮友 2024-10-13 16:45:31

不确定这是否适用于 gaetestbed,但使用 django-nose 我可以将以下内容添加到我的 settings.py 中:

NOSE_ARGS = ['--logging-clear-handlers', '--logging-filter=-root']

另一个解决方法是仅反向 grep 输出:

./manage.py test 2>&1 | egrep -v "^(root|Level)"

Not sure that this will work in gaetestbed, but using django-nose I can add the following to my settings.py:

NOSE_ARGS = ['--logging-clear-handlers', '--logging-filter=-root']

Another work-around is to just inverse grep the output:

./manage.py test 2>&1 | egrep -v "^(root|Level)"
方觉久 2024-10-13 16:45:31

这里有一个笨方法,

在你的nose/plugins/中找到capture.py和logcapture.py,

在这两个文件中找到函数addCaptureToErr,然后修改它。
(我不知道哪一个是正确的,请自行测试)

原始代码应该如下所示:

def addCaptureToErr(self, ev, output):
    return '\n'.join([str(ev) , ln('>> begin captured stdout <<'),
                      output, ln('>> end captured stdout <<')])

将其更改为

def addCaptureToErr(self, ev, output):
    check_errmsgs(output)
    return '\n'.join([str(ev) , ln('>> begin captured stdout <<'),
                      output, ln('>> end captured stdout <<')])

def check_errmsgs(self,errmsgs):
    for i in range(len(errmsgs)-1,-1,-1):
        item = errmsgs[i].split(":") 
        if(item[2].find("Evaling filter expression")):
            #find msgs you want to ignore
            del errmsgs[i]

应该可以工作。

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:

def addCaptureToErr(self, ev, output):
    return '\n'.join([str(ev) , ln('>> begin captured stdout <<'),
                      output, ln('>> end captured stdout <<')])

change it into

def addCaptureToErr(self, ev, output):
    check_errmsgs(output)
    return '\n'.join([str(ev) , ln('>> begin captured stdout <<'),
                      output, ln('>> end captured stdout <<')])

def check_errmsgs(self,errmsgs):
    for i in range(len(errmsgs)-1,-1,-1):
        item = errmsgs[i].split(":") 
        if(item[2].find("Evaling filter expression")):
            #find msgs you want to ignore
            del errmsgs[i]

It should works.

半透明的墙 2024-10-13 16:45:31

我还没有尝试过 Bigbear 的建议,但我确实找到了解决该问题的快速解决方法:将 err 输出通过管道传输到文件中。

python run_nosetests.py 2> failures.tmp
gedit failures.tmp &

这使您可以在顶部看到错误的清晰打印输出 。文件,以及其下方 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.

python run_nosetests.py 2> failures.tmp
gedit failures.tmp &

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文