From 913335f6129da1d3d66d35972a3be9012e5d0dbf Mon Sep 17 00:00:00 2001 From: boxydog Date: Fri, 31 May 2024 09:09:41 -0500 Subject: [PATCH] Fix unit tests --- pelican/log.py | 15 +++++++++++++-- pelican/tests/__init__.py | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pelican/log.py b/pelican/log.py index b60a1aef63..3eed71aed7 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -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) @@ -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__": diff --git a/pelican/tests/__init__.py b/pelican/tests/__init__.py index 564e417cf5..951cbaab71 100644 --- a/pelican/tests/__init__.py +++ b/pelican/tests/__init__.py @@ -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