Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created October 6, 2011 04:14
Show Gist options
  • Save felipe-prenholato/1266513 to your computer and use it in GitHub Desktop.
Save felipe-prenholato/1266513 to your computer and use it in GitHub Desktop.
Mock Logging Handler
class MockLoggingHandler(logging.Handler):
"""Mock logging handler to check for expected logs."""
def __init__(self, *args, **kwargs):
self.reset()
logging.Handler.__init__(self, *args, **kwargs)
def emit(self, record):
self.messages[record.levelname.lower()].append(record.getMessage())
def reset(self):
self.messages = {
'debug': [],
'info': [],
'warning': [],
'error': [],
'critical': [],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment