Skip to content

Instantly share code, notes, and snippets.

@mrchilds
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrchilds/8733191 to your computer and use it in GitHub Desktop.
Save mrchilds/8733191 to your computer and use it in GitHub Desktop.
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