File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ def __enter__(self):
47
47
logger = self .logger = logging .getLogger (self .logger_name )
48
48
formatter = logging .Formatter (self .LOGGING_FORMAT )
49
49
handler = _CapturingHandler ()
50
+ handler .setLevel (self .level )
50
51
handler .setFormatter (formatter )
51
52
self .watcher = handler .watcher
52
53
self .old_handlers = logger .handlers [:]
Original file line number Diff line number Diff line change @@ -1673,6 +1673,18 @@ def testAssertLogsFailureLevelTooHigh(self):
1673
1673
with self .assertLogs (level = 'WARNING' ):
1674
1674
log_foo .info ("1" )
1675
1675
1676
+ def testAssertLogsFailureLevelTooHigh_FilterInRootLogger (self ):
1677
+ # Failure due to level too high - message propagated to root
1678
+ with self .assertNoStderr ():
1679
+ oldLevel = log_foo .level
1680
+ log_foo .setLevel (logging .INFO )
1681
+ try :
1682
+ with self .assertRaises (self .failureException ):
1683
+ with self .assertLogs (level = 'WARNING' ):
1684
+ log_foo .info ("1" )
1685
+ finally :
1686
+ log_foo .setLevel (oldLevel )
1687
+
1676
1688
def testAssertLogsFailureMismatchingLogger (self ):
1677
1689
# Failure due to mismatching logger (and the logged message is
1678
1690
# passed through)
Original file line number Diff line number Diff line change
1
+ Fix bug where TestCase.assertLogs doesn't correctly filter messages by level.
You can’t perform that action at this time.
0 commit comments