google-app-enginenosetestssuppresssuppressmessage

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?


Solution

  • 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.