-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unittest.assertLogs passes unexpectedly #86109
Comments
Related to https://bugs.python.org/issue41898, creating a new issue after the discussion with Irit Katriel on StackOverflow (https://stackoverflow.com/a/64142338/12480730). Consider the following: import logging
import unittest
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
class TestLogging(unittest.TestCase):
def test_logging(self):
with self.assertLogs(level=logging.WARNING):
logger.info('foo') From the docs: 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. 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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: