Skip to content

Instantly share code, notes, and snippets.

@mrchilds

mrchilds/gist:8733191

Last active Aug 29, 2015
Embed
What would you like to do?
Unit Test Helpers - Mock logging
# Mock logging
# File - someclass.py
class SomeClass(object):
def method_man(self):
logging.basicConfig(filename='/tmp/somelog.log',
level=logging.INFO,
format='%(asctime)s | %(message)s',
datefmt='%m/%d/%Y %I:%M:%S')
logging = logging
logging.info('Help me')
# Test
from mock import patch
import unittest
class TestSuite(unittest.TestCase):
@patch('someclass.logging.info')
def test_adding_new_entry(self, mock_logging):
SomeClass().method_man()
log_msg = 'Help me'
mock_logging.assert_called_once_with(log_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.