MCPcopy Index your code
hub / github.com/python/cpython / test_shutdown_flush_on_close

Method test_shutdown_flush_on_close

Lib/test/test_logging.py:1238–1265  ·  view source on GitHub ↗

Test that the flush-on-close configuration is respected by the shutdown method.

(self)

Source from the content-addressed store, hash-verified

1236 self.assert_log_lines(lines) # no change
1237
1238 def test_shutdown_flush_on_close(self):
1239 """
1240 Test that the flush-on-close configuration is respected by the
1241 shutdown method.
1242 """
1243 self.mem_logger.debug(self.next_message())
1244 self.assert_log_lines([])
1245 self.mem_logger.info(self.next_message())
1246 self.assert_log_lines([])
1247 # Default behaviour is to flush on close. Check that it happens.
1248 logging.shutdown(handlerList=[logging.weakref.ref(self.mem_hdlr)])
1249 lines = [
1250 ('DEBUG', '1'),
1251 ('INFO', '2'),
1252 ]
1253 self.assert_log_lines(lines)
1254 # Now configure for flushing not to be done on close.
1255 self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
1256 self.root_hdlr,
1257 False)
1258 self.mem_logger.addHandler(self.mem_hdlr)
1259 self.mem_logger.debug(self.next_message())
1260 self.assert_log_lines(lines) # no change
1261 self.mem_logger.info(self.next_message())
1262 self.assert_log_lines(lines) # no change
1263 # assert that no new lines have been added after shutdown
1264 logging.shutdown(handlerList=[logging.weakref.ref(self.mem_hdlr)])
1265 self.assert_log_lines(lines) # no change
1266
1267 @threading_helper.requires_working_threading()
1268 def test_race_between_set_target_and_flush(self):

Callers

nothing calls this directly

Calls 6

next_messageMethod · 0.80
assert_log_linesMethod · 0.80
addHandlerMethod · 0.80
debugMethod · 0.45
infoMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected