Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃憣 Add warning log for config values that cannot be cached #12203

Merged
merged 9 commits into from
Mar 27, 2024
16 changes: 16 additions & 0 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ def test_texinfo_warnings(app, warning):
app.build(force_all=True)
warnings_exp = TEXINFO_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
_check_warnings(warnings_exp, warning.getvalue())


def test_uncacheable_config_warning(make_app, tmp_path):
picnixz marked this conversation as resolved.
Show resolved Hide resolved
"""Test than an unpickleable config value raises a warning."""
tmp_path.joinpath('conf.py').write_text("""
my_config = lambda: None
show_warning_types = True
def setup(app):
app.add_config_value('my_config', None, 'env')
""", encoding='utf-8')
tmp_path.joinpath('index.rst').write_text('Test\n====\n', encoding='utf-8')
app = make_app(srcdir=tmp_path)
app.build()
assert strip_colors(app.warning.getvalue()).strip() == (
picnixz marked this conversation as resolved.
Show resolved Hide resolved
"WARNING: cannot cache unpickable configuration value: 'my_config' [config.cache]"
)
19 changes: 0 additions & 19 deletions tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)
from sphinx.deprecation import RemovedInSphinx90Warning
from sphinx.errors import ConfigError, ExtensionError, VersionRequirementError
from sphinx.util.console import strip_colors

if TYPE_CHECKING:
from collections.abc import Iterable
Expand Down Expand Up @@ -293,24 +292,6 @@ def check(
assert counters[type(x['b'])] == 2


def test_uncacheable_config_warning(make_app, tmp_path):
"""Test than an unpickleable config value raises a warning."""
srcdir = tmp_path / 'srcdir123'
srcdir.mkdir()
srcdir.joinpath('conf.py').write_text("""
my_config = lambda: None
show_warning_types = True
def setup(app):
app.add_config_value('my_config', None, 'env')
""", encoding='utf-8')
srcdir.joinpath('index.rst').write_text('Test\n====\n', encoding='utf-8')
app = make_app(srcdir=srcdir)
app.build()
assert strip_colors(app.warning.getvalue()).strip() == (
"WARNING: cannot cache unpickable configuration value: 'my_config' [config.cache]"
)


def test_extension_values():
config = Config()

Expand Down