class_docstr: A context manager for assertLogs() and assertNoLogs() 
class_docstr_tok: ["A","context","manager","for","assertLogs","(",")","and","assertNoLogs","(",")"]
code: def __enter__(self):
      if isinstance(self.logger_name, logging.Logger):
          logger = self.logger = self.logger_name
      else:
          logger = self.logger = logging.getLogger(self.logger_name)
      formatter = logging.Formatter(self.LOGGING_FORMAT)
      handler = _CapturingHandler()
      handler.setLevel(self.level)
      handler.setFormatter(formatter)
      self.watcher = handler.watcher
      self.old_handlers = logger.handlers[:]
      self.old_level = logger.level
      self.old_propagate = logger.propagate
      logger.handlers = [handler]
      logger.setLevel(self.level)
      logger.propagate = False
      if self.no_logs:
          return
      return handler.watcher
  
file_path: cpython/Lib/unittest/_log.py
imports: import logging
  import collections
  from .case import _BaseTestCaseContext
label_desc: Use image node_id 2 for calling the _AssertLogsContext obj's underlying member method code with example usage: obj.__enter__() and returns: handler