Last active
August 15, 2019 20:36
-
-
Save jdesilvio/7327a8ec100cd25237fd9f7530346e32 to your computer and use it in GitHub Desktop.
Python logger patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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