Fixes issue #11314 -

This commit is contained in:
Sharad Nair 2023-09-17 12:08:55 +05:30
parent 6c2feb75d2
commit d9697395d0
2 changed files with 9 additions and 7 deletions

View File

@ -303,13 +303,13 @@ def pytest_addoption(parser: Parser) -> None:
add_option_ini( add_option_ini(
"--log-file-format", "--log-file-format",
dest="log_file_format", dest="log_file_format",
default=DEFAULT_LOG_FORMAT, default=None,
help="Log format used by the logging module", help="Log format used by the logging module",
) )
add_option_ini( add_option_ini(
"--log-file-date-format", "--log-file-date-format",
dest="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", help="Log date format used by the logging module",
) )
add_option_ini( add_option_ini(
@ -635,7 +635,9 @@ class LoggingPlugin:
self.report_handler.setFormatter(self.formatter) self.report_handler.setFormatter(self.formatter)
# File logging. # 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 log_file = get_option_ini(config, "log_file") or os.devnull
if log_file != os.devnull: if log_file != os.devnull:
directory = os.path.dirname(os.path.abspath(log_file)) directory = os.path.dirname(os.path.abspath(log_file))

View File

@ -77,14 +77,14 @@ def test_root_logger_affected(pytester: Pytester) -> None:
assert "warning text going to logger" not in stdout assert "warning text going to logger" not in stdout
assert "info 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 # The log file should only contain the error log messages and
# not the info one, because the default level of the root logger is # not the warning or info ones, because the root logger is set to
# WARNING. # ERROR using --log-level=ERROR.
assert os.path.isfile(log_file) assert os.path.isfile(log_file)
with open(log_file, encoding="utf-8") as rfh: with open(log_file, encoding="utf-8") as rfh:
contents = rfh.read() contents = rfh.read()
assert "info text going to logger" not in contents 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 assert "error text going to logger" in contents