TestRevertAndConvertAttrs.assertLogs#
- TestRevertAndConvertAttrs.assertLogs(logger=None, level=None)#
Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.
This method must be used as a context manager, and will yield a recording object with two attributes:
outputandrecords. At the end of the context manager, theoutputattribute will be a list of the matching formatted log messages and therecordsattribute will be a list of the corresponding LogRecord objects.Example:
with self.assertLogs('foo', level='INFO') as cm: logging.getLogger('foo').info('first message') logging.getLogger('foo.bar').error('second message') self.assertEqual(cm.output, ['INFO:foo:first message', 'ERROR:foo.bar:second message'])