MCPcopy Create free account
hub / github.com/pytest-dev/pytest / set_level

Method set_level

src/_pytest/logging.py:441–457  ·  view source on GitHub ↗

Set the level of a logger for the duration of a test. .. versionchanged:: 3.4 The levels of the loggers changed by this function will be restored to their initial values at the end of the test. :param int level: The level. :param str logger: The logg

(self, level: Union[int, str], logger: Optional[str] = None)

Source from the content-addressed store, hash-verified

439 self.handler.reset()
440
441 def set_level(self, level: Union[int, str], logger: Optional[str] = None) -> None:
442 """Set the level of a logger for the duration of a test.
443
444 .. versionchanged:: 3.4
445 The levels of the loggers changed by this function will be
446 restored to their initial values at the end of the test.
447
448 :param int level: The level.
449 :param str logger: The logger to update. If not given, the root logger.
450 """
451 logger_obj = logging.getLogger(logger)
452 # Save the original log-level to restore it during teardown.
453 self._initial_logger_levels.setdefault(logger, logger_obj.level)
454 logger_obj.setLevel(level)
455 if self._initial_handler_level is None:
456 self._initial_handler_level = self.handler.level
457 self.handler.setLevel(level)
458
459 @contextmanager
460 def at_level(

Callers 7

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 1

setdefaultMethod · 0.80

Tested by 7

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