Skip to content

Instantly share code, notes, and snippets.

@jdesilvio
Last active August 15, 2019 20:36
Show Gist options
  • Save jdesilvio/7327a8ec100cd25237fd9f7530346e32 to your computer and use it in GitHub Desktop.
Save jdesilvio/7327a8ec100cd25237fd9f7530346e32 to your computer and use it in GitHub Desktop.
Python logger patch
from logging import Logger
import unittest
from mock import Mock, patch
class MyClassTest(unittest.TestCase):
def setUp(self):
self._logger = Mock(spec=Logger)
self.logging_patch = patch(
"my.module.logging", spec=True
)
mock_logging = self.logging_patch.start()
mock_logging.getLogger.side_effect = [Mock(spec=Logger), self._logger]
def tearDown(self):
self.logging_patch.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment