diff --git a/tobiko/config.py b/tobiko/config.py index 4bad82e4a..33022466a 100644 --- a/tobiko/config.py +++ b/tobiko/config.py @@ -46,7 +46,14 @@ LOGGING_CONF_GROUP_NAME = "logging" LOGGING_OPTIONS = [ cfg.BoolOpt('capture_log', default=True, - help="Whenever to capture LOG during test case execution"), + help="Whenever to report debugging log lines"), + cfg.StrOpt('line_format', + default=('%(asctime)s.%(msecs)03d %(process)d %(levelname)s ' + '%(name)s - %(message)s'), + help='Default logging line format string'), + cfg.StrOpt('date_format', + default='%Y-%m-%d %H:%M:%S', + help='Default logging date format string'), ] HTTP_CONF_GROUP_NAME = "http" diff --git a/tobiko/tests/conftest.py b/tobiko/tests/conftest.py index 29c013622..0862c5d5c 100644 --- a/tobiko/tests/conftest.py +++ b/tobiko/tests/conftest.py @@ -50,35 +50,35 @@ def configure_metadata(config): def configure_caplog(config): tobiko_config = tobiko.tobiko_config() - if tobiko_config.logging.capture_log is True: + if tobiko_config.logging.capture_log: if tobiko_config.debug: - default = 'DEBUG' + level = 'DEBUG' else: - default = 'INFO' + level = 'INFO' else: - default = 'FATAL' + level = 'FATAL' for key in ['log_level', 'log_file_level', 'log_cli_level']: - set_default_inicfg(config, key, default) + set_default_inicfg(config, key, level) - default = tobiko_config.logging_default_format_string - if default: + line_format: str = tobiko_config.logging.line_format + if line_format: # instance and color are not supported by pytest - default = default.replace('%(instance)s', '') - default = default.replace('%(color)s', '') - if default: + line_format = line_format.replace('%(instance)s', '') + line_format = line_format.replace('%(color)s', '') + if line_format: for key in ['log_format', 'log_file_format', 'log_cli_format']: - set_default_inicfg(config, key, default) + set_default_inicfg(config, key, line_format) - default = tobiko_config.log_date_format - if default: + date_format = tobiko_config.logging.date_format + if date_format: for key in ['log_date_format', 'log_file_date_format', 'log_cli_date_format']: - set_default_inicfg(config, key, default) + set_default_inicfg(config, key, date_format) def configure_junitxml(config): @@ -87,10 +87,8 @@ def configure_junitxml(config): def set_default_inicfg(config, key, default): value = config.inicfg.setdefault(key, default) - if value != default: - LOG.debug(f"Set default inicfg: {key} = {value}") - else: - LOG.debug(f"Keep existing inicfg: {key} = {value}") + if value == default: + LOG.debug(f"Set default inicfg: {key} = {value!r}") class TestRunnerTimeoutManager(tobiko.SharedFixture): diff --git a/tobiko/tests/unit/test_conftest.py b/tobiko/tests/unit/test_conftest.py index b5637cec5..ee6e63d49 100644 --- a/tobiko/tests/unit/test_conftest.py +++ b/tobiko/tests/unit/test_conftest.py @@ -55,25 +55,32 @@ class CaplogTest(unit.TobikoUnitTest): self.assertEqual('FATAL', pytest_config.inicfg['log_level']) def test_configure_caplog_log_format(self): - self.patch_caplog_config(log_format='') + self.patch_caplog_config(line_format='') pytest_config = mock.MagicMock(inicfg={}) conftest.configure_caplog(pytest_config) self.assertEqual('', pytest_config.inicfg['log_format']) - def test_configure_caplog_log_date_format(self): - self.patch_caplog_config(log_date_format='') + def test_configure_caplog_date_format(self): + self.patch_caplog_config(date_format='') pytest_config = mock.MagicMock(inicfg={}) conftest.configure_caplog(pytest_config) self.assertEqual('', pytest_config.inicfg['log_date_format']) - def patch_caplog_config(self, capture_log=False, debug=False, - log_format=None, log_date_format=None): + def patch_caplog_config(self, + capture_log: bool = None, + debug: bool = None, + line_format: str = None, + date_format: str = None): tobiko_config = self.patch(tobiko, 'tobiko_config').return_value - tobiko_config.logging.capture_log = capture_log - tobiko_config.debug = debug - tobiko_config.logging_default_format_string = log_format - tobiko_config.log_date_format = log_date_format + if capture_log is not None: + tobiko_config.logging.capture_log = capture_log + if debug is not None: + tobiko_config.debug = debug + if line_format is not None: + tobiko_config.logging.line_format = line_format + if date_format is not None: + tobiko_config.logging.date_format = date_format class TimeoutTest(unit.TobikoUnitTest):