@@ -1936,6 +1936,35 @@ def testAssertLogsWithFormatter(self):
19361936 self .assertEqual (cm .output , ["[No.1: the larch] INFO:foo:1" ])
19371937 self .assertLogRecords (cm .records , [{'name' : 'foo' }])
19381938
1939+ def testAssertLogsWithNOTSET (self ):
1940+ # Check that logging.NOTSET level is handled correctly
1941+ # (not treated as falsey and defaulted to INFO)
1942+ with self .assertNoStderr ():
1943+ with self .assertLogs (level = logging .NOTSET ) as cm :
1944+ log_foo .info ("1" )
1945+ log_foobar .debug ("2" )
1946+ log_quux .error ("3" )
1947+ self .assertEqual (cm .output , ["INFO:foo:1" , "DEBUG:foo.bar:2" , "ERROR:quux:3" ])
1948+ self .assertLogRecords (cm .records , [
1949+ {'name' : 'foo' , 'levelno' : logging .INFO },
1950+ {'name' : 'foo.bar' , 'levelno' : logging .DEBUG },
1951+ {'name' : 'quux' , 'levelno' : logging .ERROR }
1952+ ])
1953+
1954+ def testAssertNoLogsWithNOTSET (self ):
1955+ # Check that logging.NOTSET level is handled correctly in assertNoLogs
1956+ # (not treated as falsey and defaulted to INFO)
1957+ with self .assertNoStderr ():
1958+ with self .assertNoLogs (level = logging .NOTSET ):
1959+ pass
1960+
1961+ with self .assertRaises (self .failureException ) as cm :
1962+ with self .assertNoLogs (level = logging .NOTSET ):
1963+ log_foo .debug ("debug message" )
1964+
1965+ self .assertIn ("Unexpected logs found" , str (cm .exception ))
1966+ self .assertIn ("DEBUG:foo:debug message" , str (cm .exception ))
1967+
19391968 def testAssertNoLogsDefault (self ):
19401969 with self .assertRaises (self .failureException ) as cm :
19411970 with self .assertNoLogs ():
0 commit comments