Skip to content

Commit f9a6ec9

Browse files
committed
test(typehints-gp[field-xref]) Module-scope lambda-default fixture
why: PR #36 review caught a function-scoped Sphinx build inside `test_unsupported_default_falls_back_to_plain_text` — CLAUDE.md requires every integration test's Sphinx build to live in a module- or session-scoped fixture so the build cost is shared across runs. The three sibling tests in the file already follow the rule; this one was the outlier because it was the last test added and used a one-off scenario. what: - Hoist the lambda fixture project's module source into a module-level `_LAMBDA_MODULE_SOURCE` constant alongside the existing `_DATA_ATTRIBUTE_MODULE_SOURCE` and `_CROSS_MODULE_*` constants. - Add `lambda_default_html_result` as a `@pytest.fixture(scope="module")` wrapping `build_shared_sphinx_result`, mirroring the existing three fixtures in shape (parameter list, scenario construction, `purge_modules=("lambda_demo",)` argument). - Convert `test_unsupported_default_falls_back_to_plain_text` to consume the fixture parameter and call `read_output` directly; the two assertions are unchanged so the test still pins the plain-text-fallback contract for unparseable lambda defaults.
1 parent 8dc90a0 commit f9a6ec9

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

tests/ext/typehints_gp/test_default_xref_integration.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,26 @@ def test_cross_module_default_resolves_via_refspecific(
291291
assert 'class="xref py py-obj' in html
292292

293293

294-
@pytest.mark.integration
295-
def test_unsupported_default_falls_back_to_plain_text(
296-
tmp_path_factory: pytest.TempPathFactory,
297-
) -> None:
298-
"""Unparseable defaults (lambdas) leave the span as plain text."""
299-
module_source = textwrap.dedent(
300-
"""\
301-
from __future__ import annotations
294+
_LAMBDA_MODULE_SOURCE = textwrap.dedent(
295+
"""\
296+
from __future__ import annotations
302297
303298
304-
def has_lambda_default(callback=lambda: 1) -> None:
305-
\"\"\"Function with a lambda default.\"\"\"
306-
"""
307-
)
299+
def has_lambda_default(callback=lambda: 1) -> None:
300+
\"\"\"Function with a lambda default.\"\"\"
301+
"""
302+
)
303+
304+
305+
@pytest.fixture(scope="module")
306+
def lambda_default_html_result(
307+
tmp_path_factory: pytest.TempPathFactory,
308+
) -> SharedSphinxResult:
309+
"""Build a project with a lambda default exercising the plain-text fallback."""
308310
cache_root = tmp_path_factory.mktemp("default-xref-lambda-html")
309311
scenario = SphinxScenario(
310312
files=(
311-
ScenarioFile("lambda_demo.py", module_source),
313+
ScenarioFile("lambda_demo.py", _LAMBDA_MODULE_SOURCE),
312314
ScenarioFile(
313315
"conf.py",
314316
_CONF_PY.replace("__SCENARIO_SRCDIR__", SCENARIO_SRCDIR_TOKEN),
@@ -327,12 +329,19 @@ def has_lambda_default(callback=lambda: 1) -> None:
327329
),
328330
),
329331
)
330-
result = build_shared_sphinx_result(
332+
return build_shared_sphinx_result(
331333
cache_root,
332334
scenario,
333335
purge_modules=("lambda_demo",),
334336
)
335-
html = read_output(result, "index.html")
337+
338+
339+
@pytest.mark.integration
340+
def test_unsupported_default_falls_back_to_plain_text(
341+
lambda_default_html_result: SharedSphinxResult,
342+
) -> None:
343+
"""Unparseable defaults (lambdas) leave the span as plain text."""
344+
html = read_output(lambda_default_html_result, "index.html")
336345

337346
# The lambda text appears in the rendered output but not wrapped in an xref
338347
assert "lambda" in html

0 commit comments

Comments
 (0)