From d9697395d05c7931e44da0d9b5bb3c6ce32274bf Mon Sep 17 00:00:00 2001 From: Sharad Nair <134932980+SharadNair7@users.noreply.github.com> Date: Sun, 17 Sep 2023 12:08:55 +0530 Subject: [PATCH] Fixes issue #11314 - --- src/_pytest/logging.py | 8 +++++--- testing/logging/test_reporting.py | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 245b7aed0..bacca4b2a 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -303,13 +303,13 @@ def pytest_addoption(parser: Parser) -> None: add_option_ini( "--log-file-format", dest="log_file_format", - default=DEFAULT_LOG_FORMAT, + default=None, help="Log format used by the logging module", ) add_option_ini( "--log-file-date-format", dest="log_file_date_format", - default=DEFAULT_LOG_DATE_FORMAT, + default=None, help="Log date format used by the logging module", ) add_option_ini( @@ -635,7 +635,9 @@ class LoggingPlugin: self.report_handler.setFormatter(self.formatter) # File logging. - self.log_file_level = get_log_level_for_setting(config, "log_file_level") + self.log_file_level = get_log_level_for_setting( + config, "log_file_level", "log_level" + ) log_file = get_option_ini(config, "log_file") or os.devnull if log_file != os.devnull: directory = os.path.dirname(os.path.abspath(log_file)) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index 8c1e4f8cc..679ad9bae 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -77,14 +77,14 @@ def test_root_logger_affected(pytester: Pytester) -> None: assert "warning text going to logger" not in stdout assert "info text going to logger" not in stdout - # The log file should contain the warning and the error log messages and - # not the info one, because the default level of the root logger is - # WARNING. + # The log file should only contain the error log messages and + # not the warning or info ones, because the root logger is set to + # ERROR using --log-level=ERROR. assert os.path.isfile(log_file) with open(log_file, encoding="utf-8") as rfh: contents = rfh.read() assert "info text going to logger" not in contents - assert "warning text going to logger" in contents + assert "warning text going to logger" not in contents assert "error text going to logger" in contents