Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

testing logging python

# 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'])
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #testing #logging #python
ADD COMMENT
Topic
Name
7+1 =