From 479e48266c025c99025787a8004a82b2afda8e6c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 28 May 2022 19:17:46 +0100 Subject: [PATCH] Update warning, revert my original warning patch --- sphinx/config.py | 15 ++++++--------- tests/test_config.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/sphinx/config.py b/sphinx/config.py index 0233cbbd139..1cd0632ed94 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -165,18 +165,15 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi confdir) namespace = eval_config_file(filename, tags) - # Note: Old sphinx projects has been configured as "langugae = None" because - # sphinx-quickstart had generated the configuration by default formerly. + # Note: Old sphinx projects have been configured as "langugae = None" because + # sphinx-quickstart previously generated this by default. # To keep compatibility, they should be fallback to 'en' for a while - # (At least 2 years or more since v5.0 release). + # (This conversion should not be removed before 2025-01-01). if namespace.get("language", ...) is None: - logging.warning(__("Invalid configuration found: 'language = None'. " - "Now it takes only a string. Please update your configuration. " - "Fallback to 'en' (English).")) + logger.warning(__("Invalid configuration value found: 'language = None'. " + "Update your configuration to a valid langauge code. " + "Falling back to 'en' (English).")) namespace["language"] = "en" - warnings.warn("'None' is not a valid value for 'language', coercing to 'en'. " - "Update 'conf.py' to a valid language code to silence this " - "warning.", RuntimeWarning, stacklevel=4) return cls(namespace, overrides or {}) diff --git a/tests/test_config.py b/tests/test_config.py index 8d707ae252b..ec8194af11a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -397,20 +397,22 @@ def test_conf_py_language_none(tempdir): assert cfg.language == "en" -def test_conf_py_language_none_warning(tempdir): +def test_conf_py_language_none_warning(tempdir, caplog): """Regression test for #10474.""" # Given a conf.py file with language = None (tempdir / 'conf.py').write_text("language = None", encoding='utf-8') + # When we load conf.py into a Config object + Config.read(tempdir, {}, None) + # Then a warning is raised - with pytest.warns( - RuntimeWarning, - match="'None' is not a valid value for 'language', coercing to 'en'. " - "Update 'conf.py' to a valid language code to silence this " - "warning."): - # When we load conf.py into a Config object - Config.read(tempdir, {}, None) + assert len(caplog.messages) == 1 + assert caplog.messages[0] == ( + "Invalid configuration value found: 'language = None'. " + "Update your configuration to a valid langauge code. " + "Falling back to 'en' (English).") + assert caplog.records[0].levelname == "WARNING" def test_conf_py_no_language(tempdir):