Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I suppress App Engine logging while running unit tests?

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?

like image 998
Matt Norris Avatar asked Dec 07 '10 03:12

Matt Norris


2 Answers

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)"
like image 164
Conley Owens Avatar answered Nov 02 '22 01:11

Conley Owens


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.

like image 41
KTU Avatar answered Nov 01 '22 23:11

KTU