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

Method _force_enable_logging

src/_pytest/logging.py:510–542  ·  view source on GitHub ↗

Enable the desired logging level if the global level was disabled via ``logging.disabled``. Only enables logging levels greater than or equal to the requested ``level``. Does nothing if the desired ``level`` wasn't disabled. :param level: The logger level caplo

(
        self, level: int | str, logger_obj: logging.Logger
    )

Source from the content-addressed store, hash-verified

508 self.handler.clear()
509
510 def _force_enable_logging(
511 self, level: int | str, logger_obj: logging.Logger
512 ) -> int:
513 """Enable the desired logging level if the global level was disabled via ``logging.disabled``.
514
515 Only enables logging levels greater than or equal to the requested ``level``.
516
517 Does nothing if the desired ``level`` wasn't disabled.
518
519 :param level:
520 The logger level caplog should capture.
521 All logging is enabled if a non-standard logging level string is supplied.
522 Valid level strings are in :data:`logging._nameToLevel`.
523 :param logger_obj: The logger object to check.
524
525 :return: The original disabled logging level.
526 """
527 original_disable_level: int = logger_obj.manager.disable
528
529 if isinstance(level, str):
530 # Try to translate the level string to an int for `logging.disable()`
531 level = logging.getLevelName(level) # type: ignore[deprecated]
532
533 if not isinstance(level, int):
534 # The level provided was not valid, so just un-disable all logging.
535 logging.disable(logging.NOTSET)
536 elif not logger_obj.isEnabledFor(level):
537 # Each level is `10` away from other levels.
538 # https://docs.python.org/3/library/logging.html#logging-levels
539 disable_level = max(level - 10, logging.NOTSET)
540 logging.disable(disable_level)
541
542 return original_disable_level
543
544 def set_level(self, level: int | str, logger: str | None = None) -> None:
545 """Set the threshold level of a logger for the duration of a test.

Callers 3

set_levelMethod · 0.95
at_levelMethod · 0.95

Calls

no outgoing calls

Tested by 1