MCPcopy
hub / github.com/pytest-dev/pytest / set_level

Method set_level

src/_pytest/logging.py:544–567  ·  src/_pytest/logging.py::LogCaptureFixture.set_level

Set the threshold level of a logger for the duration of a test. Logging messages which are less severe than this level will not be captured. .. versionchanged:: 3.4 The levels of the loggers changed by this function will be restored to their initial values a

(self, level: int | str, logger: str | None = None)

Source from the content-addressed store, hash-verified

542 return original_disable_level
543
544 def set_level(self, level: int | str, logger: str | None = None) -> None:
545 class="st">"""Set the threshold level of a logger for the duration of a test.
546
547 Logging messages which are less severe than this level will not be captured.
548
549 .. versionchanged:: 3.4
550 The levels of the loggers changed by this function will be
551 restored to their initial values at the end of the test.
552
553 Will enable the requested logging level if it was disabled via :func:`logging.disable`.
554
555 :param level: The level.
556 :param logger: The logger to update. If not given, the root logger.
557 class="st">"""
558 logger_obj = logging.getLogger(logger)
559 class="cm"># Save the original log-level to restore it during teardown.
560 self._initial_logger_levels.setdefault(logger, logger_obj.level)
561 logger_obj.setLevel(level)
562 if self._initial_handler_level is None:
563 self._initial_handler_level = self.handler.level
564 self.handler.setLevel(level)
565 initial_disabled_logging_level = self._force_enable_logging(level, logger_obj)
566 if self._initial_disabled_logging_level is None:
567 self._initial_disabled_logging_level = initial_disabled_logging_level
568
569 @contextmanager
570 def at_level(self, level: int | str, logger: str | None = None) -> Generator[None]:

Callers 8

test_change_levelFunction · 0.80
test_log_accessFunction · 0.80
test_messagesFunction · 0.80
test_record_tuplesFunction · 0.80
test_unicodeFunction · 0.80
test_clearFunction · 0.80

Calls 2

_force_enable_loggingMethod · 0.95
setdefaultMethod · 0.80

Tested by 8

test_change_levelFunction · 0.64
test_log_accessFunction · 0.64
test_messagesFunction · 0.64
test_record_tuplesFunction · 0.64
test_unicodeFunction · 0.64
test_clearFunction · 0.64