1# can be done by using unittest's assertLogs
2
3from unittest import TestCase
4
5class MyTest(TestCase):
6
7 def test_logs(self):
8 with self.assertLogs('foo', level='INFO') as cm:
9 logging.getLogger('foo').info('first message')
10 logging.getLogger('foo.bar').error('second message')
11 self.assertEqual(cm.output, ['INFO:foo:first message',
12 'ERROR:foo.bar:second message'])