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 mrbean-bremen
Recipients mrbean-bremen
Date 2020-10-05.14:39:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Related to, creating a new issue after the discussion with Irit Katriel on StackOverflow (

Consider the following:

import logging
import unittest

logger = logging.getLogger(__name__)

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

From the docs:
The test passes if at least one message emitted inside the with block matches the logger and level conditions, otherwise it fails.

This means that this test should fail (nothing has been logged at warning level or above), but it passes. 

The reason is that in the assertLogs context manager, the log level of the passed logger is temporarily set to the passed level, and if no logging has happened on exit, the test will fail. 
If no logger is passed into the call, the temporary log level is set in the root level. If any descendant logger has it's own log level set (as in this example to INFO), this logger will still log at it's own level, and the test will pass. 

This will always happen on the condition that a descendent of the passed logger has it's own log level set that is smaller than the asserted level, and it does some logging at this level inside the assertLog context manager.
Date User Action Args
2020-10-05 14:40:00mrbean-bremensetrecipients: + mrbean-bremen
2020-10-05 14:40:00mrbean-bremensetmessageid: <>
2020-10-05 14:39:59mrbean-bremenlinkissue41943 messages
2020-10-05 14:39:59mrbean-bremencreate