import logging
from testfixtures import LogCapture
with LogCapture() as l:
    logger = logging.getLogger()
logger.info('a message')
logger.error('an error')
Writing a unit test for Python logger formatted output