bpo-41943: Fix bug where assertLogs doesn't correctly filter messages… (GH-22565)
… by level @vsajip , @pitrou Automerge-Triggered-By: GH:vsajip
This commit is contained in:
parent
aca67da4fe
commit
6fdfcec5b1
|
@ -47,6 +47,7 @@ class _AssertLogsContext(_BaseTestCaseContext):
|
||||||
logger = self.logger = logging.getLogger(self.logger_name)
|
logger = self.logger = logging.getLogger(self.logger_name)
|
||||||
formatter = logging.Formatter(self.LOGGING_FORMAT)
|
formatter = logging.Formatter(self.LOGGING_FORMAT)
|
||||||
handler = _CapturingHandler()
|
handler = _CapturingHandler()
|
||||||
|
handler.setLevel(self.level)
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
self.watcher = handler.watcher
|
self.watcher = handler.watcher
|
||||||
self.old_handlers = logger.handlers[:]
|
self.old_handlers = logger.handlers[:]
|
||||||
|
|
|
@ -1673,6 +1673,18 @@ test case
|
||||||
with self.assertLogs(level='WARNING'):
|
with self.assertLogs(level='WARNING'):
|
||||||
log_foo.info("1")
|
log_foo.info("1")
|
||||||
|
|
||||||
|
def testAssertLogsFailureLevelTooHigh_FilterInRootLogger(self):
|
||||||
|
# Failure due to level too high - message propagated to root
|
||||||
|
with self.assertNoStderr():
|
||||||
|
oldLevel = log_foo.level
|
||||||
|
log_foo.setLevel(logging.INFO)
|
||||||
|
try:
|
||||||
|
with self.assertRaises(self.failureException):
|
||||||
|
with self.assertLogs(level='WARNING'):
|
||||||
|
log_foo.info("1")
|
||||||
|
finally:
|
||||||
|
log_foo.setLevel(oldLevel)
|
||||||
|
|
||||||
def testAssertLogsFailureMismatchingLogger(self):
|
def testAssertLogsFailureMismatchingLogger(self):
|
||||||
# Failure due to mismatching logger (and the logged message is
|
# Failure due to mismatching logger (and the logged message is
|
||||||
# passed through)
|
# passed through)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix bug where TestCase.assertLogs doesn't correctly filter messages by level.
|
Loading…
Reference in New Issue