def test_import_custom_logger(self): """Test if custom logger class can be imported""" reload_module(actionlogger) self.assertEqual(True, actionlogger._found_logger) # Check there is no instance of logger created on import self.mock_logger.Logger.assert_not_called() active_logger = actionlogger.ActionLogger() self.assertEqual(actionlogger._CustomLogger, type(active_logger))
def test_import_clash(self): """Test a custom logger import clash: issue #315""" # Re-patch for this specific test: # we have a module with a name 'logger' and even a 'Logger' object # but there is no 'sectionStart' attribute in the object self.module_patcher.stop() self.mock_logger.Logger.sectionStart = None self.module_patcher = mock.patch.dict('sys.modules', self.modules) self.module_patcher.start() reload_module(actionlogger) self.assertEqual(False, actionlogger._found_logger) # Verify the fallback to the standard logger active_logger = actionlogger.ActionLogger() self.assertEqual(actionlogger._StandardLogger, type(active_logger))