class_docstr: Attaches to the logging module and captures log messages for each test.
      
class_docstr_tok: ["Attaches","to","the","logging","module","and","captures","log","messages","for","each","test","."]
docstr: Implements the internals of pytest_runtest_xxx() hook.
docstr_tok: ["Implements","the","internals","of","pytest_runtest_xxx","(",")","hook","."]
code: def _runtest_for_main(self, item, when):
      """Implements the internals of pytest_runtest_xxx() hook."""
      with catching_logs(
          LogCaptureHandler(),
          formatter=self.formatter,
          level=self.log_level,
      ) as log_handler:
          if self.log_cli_handler:
              self.log_cli_handler.set_when(when)
  
          if item is None:
              yield  # run the test
              return
  
          if not hasattr(item, "catch_log_handlers"):
              item.catch_log_handlers = {}
          item.catch_log_handlers[when] = log_handler
          item.catch_log_handler = log_handler
          try:
              yield  # run test
          finally:
              if when == "teardown":
                  del item.catch_log_handler
                  del item.catch_log_handlers
  
          if self.print_logs:
              # Add a captured log section to the report.
              log = log_handler.stream.getvalue().strip()
              item.add_report_section(when, "log", log)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import logging
  import re
  from contextlib import contextmanager
  import py
  import six
  import pytest
  from _pytest.compat import dummy_context_manager
  from _pytest.config import create_terminal_writer
  from _pytest.pathlib import Path
label_desc: Use image node_id 8 for calling the LoggingPlugin obj's underlying member method code with example usage: obj._runtest_for_main(item, when) without return types