Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxydog committed May 31, 2024
1 parent d8e4563 commit 913335f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pelican/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def init(
name=None,
logs_dedup_min_level=None,
):
"""Initialize the logger.
:param level: the log level
:param fatal: how to set up the FatalLogger. If "warning", then warnings are fatal.
If fatal is set (including to 'ignore'!) then errors are fatal.
Pass an empty string '' for errors to be non-fatal.
:param handler: the logging handler
:param name: the name of the logger to use
:param logs_dedup_min_level: the LimitFilter.LOGS_DEDUP_MIN_LEVEL to use
"""
FatalLogger.warnings_fatal = fatal.startswith("warning")
FatalLogger.errors_fatal = bool(fatal)

Expand All @@ -155,12 +165,13 @@ def init(
LimitFilter.LOGS_DEDUP_MIN_LEVEL = logs_dedup_min_level


def log_warnings():
def log_warnings(fatal: str) -> None:
"""Redirect warnings module to use logging instead."""
import warnings

logging.captureWarnings(True)
warnings.simplefilter("default", DeprecationWarning)
init(logging.DEBUG, name="py.warnings")
init(logging.DEBUG, name="py.warnings", fatal=fatal)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion pelican/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pelican.log import log_warnings

# redirect warnings module to use logging instead
log_warnings()
# The "" of the fatal argument means "don't raise on logging an error"
log_warnings("")

# setup warnings to log DeprecationWarning's and error on
# warnings in pelican's codebase
Expand Down

0 comments on commit 913335f

Please sign in to comment.