This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author udalrich.schermer
Recipients udalrich.schermer
Date 2020-09-30.19:13:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The following test code unexpectedly passes.

import logging
import unittest

LOG_FORMAT = '%(levelname)-10s %(asctime)s: %(message)s'

def set_up_logger(app_name, level=logging.INFO, file="test.log"):
    formatter = logging.Formatter(LOG_FORMAT)
    log = logging.getLogger(app_name)
    # The next line lets the test pass
    return log

logger = set_up_logger(__name__)

class TestLogging(unittest.TestCase):
    def test_logging(self):
        with self.assertLogs(level=logging.WARNING):

Based on discussion at, it appears that I need to pass in the logger which is going to be doing the logging.  

Doing so would make the test over-specific and fragile.  The requirement is that a warning be logged, not that a specific logger issue the warning.

This was verified with Python 3.8.5 on a Mac, but probably exists in most/all other versions.
Date User Action Args
2020-09-30 19:13:37udalrich.schermersetrecipients: + udalrich.schermer
2020-09-30 19:13:37udalrich.schermersetmessageid: <>
2020-09-30 19:13:37udalrich.schermerlinkissue41898 messages
2020-09-30 19:13:37udalrich.schermercreate