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 <1601493217.83.0.77998878518.issue41898@roundup.psfhosted.org>
In-reply-to
Content
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
    log.setLevel(level)
    return log

logger = set_up_logger(__name__)

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

Based on discussion at https://stackoverflow.com/questions/64141681/any-level-of-logging-lets-assertlogs-pass, 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.
History
Date User Action Args
2020-09-30 19:13:37udalrich.schermersetrecipients: + udalrich.schermer
2020-09-30 19:13:37udalrich.schermersetmessageid: <1601493217.83.0.77998878518.issue41898@roundup.psfhosted.org>
2020-09-30 19:13:37udalrich.schermerlinkissue41898 messages
2020-09-30 19:13:37udalrich.schermercreate