📜  测试记录 python 代码示例

📅  最后修改于: 2022-03-11 14:45:03.936000             🧑  作者: Mango

代码示例2
# can be done by using unittest's assertLogs

from unittest import TestCase

class MyTest(TestCase):
  
  def test_logs(self):
    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'])