tests.sphinx.conftest moduleΒΆ
Fixtures and helpers for Sphinx tests.
Separated from the root tests/conftest.py so that the Sphinx dependency
(and its ecosystem: myst-parser, docutils, etc.) is only imported when running
the tests in this subdirectory.
- class tests.sphinx.conftest.FormatType(*values)[source]ΒΆ
Bases:
EnumSphinx document format types and their file extensions.
- RST = '.rst'ΒΆ
- MYST = '.md'ΒΆ
- class tests.sphinx.conftest.SphinxAppWrapper(app, format_type)[source]ΒΆ
Bases:
objectWrapper around Sphinx application with additional testing methods.
- classmethod create(format_type, tmp_path, return_srcdir=False, enable_exec_directives=True)[source]ΒΆ
Factory method to create a SphinxAppWrapper with given format.
enable_exec_directivesopts the test app into theclick:*andpython:*directive families. Defaults toTruefor every fixture-built app because the test suite primarily exercises those directives. Tests that verify the off-by-default production gate flip the flag back toFalseexplicitly.- Return type:
Generator[SphinxAppWrapper|tuple[SphinxAppWrapper,Path],None,None]
- tests.sphinx.conftest.sphinx_app(request, tmp_path)[source]ΒΆ
Create a Sphinx application for testing.
- tests.sphinx.conftest.sphinx_app_for_format(request, tmp_path)[source]ΒΆ
sphinx_appvariant whose format is supplied by the caller.Identical to
sphinx_app()but without the defaultparams: theFormatTypeis taken from the testβs indirect parametrization. Aparams-bearing fixture cannot also be parametrized by a test (pytest rejects it as a duplicate parametrization), so a test that drives the format per case parametrizes this variant instead, usually throughformat_params().
- tests.sphinx.conftest.sphinx_app_rst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing RST format only.
The
click:*andpython:*directive families are enabled so tests can exercise them. Tests that explicitly verify the off-by- default opt-in gate construct their own app viaSphinxAppWrapper.create()withenable_exec_directives=False.
- tests.sphinx.conftest.sphinx_app_myst(tmp_path)[source]ΒΆ
Create a Sphinx application for testing MyST format only.
The
click:*andpython:*directive families are enabled: seesphinx_app_rst()for the rationale.
- tests.sphinx.conftest.sphinx_app_myst_with_include(tmp_path)[source]ΒΆ
Create a Sphinx application for testing MyST format with include files.
- class tests.sphinx.conftest.DirectiveTestCase(name, format_type=None, source_block=None, run_block=None, document=None, html_matches=None)[source]ΒΆ
Bases:
objectTest case data for directive tests.
- format_type: FormatType | None = NoneΒΆ
- tests.sphinx.conftest.format_params(*test_cases)[source]ΒΆ
Pair each test case with every document format it is written for.
Feeds the indirect parametrization of
sphinx_app_for_format(), so a case is only ever built by an app whose format it can render: a case pinned to aFormatTypeyields that format alone, a format-agnostic one yields a parameter per format.- Return type:
- tests.sphinx.conftest.unescape_quotes(text)[source]ΒΆ
Replace quote entities with bare quotes, so both escapings compare equal.
Pygments 2.21.0 replaced its
escape_html()helper withhtml.escape(value, quote=False). Token text carries bare"and'since then, where older releases produced"and'. Both forms render the same, and thepygmentsextra declares a floor spanning that release, so HTML fragments are compared with quotes normalized.- Return type:
- tests.sphinx.conftest.plain_whitespace(text)[source]ΒΆ
Replace whitespace tokens with bare spaces, so both lexings compare equal.
Pygments 2.19.0 made the Python lexer emit some blanks of a
deforfromstatement as whitespace tokens, where older releases leave them as bare text. Both forms render the same, and thesphinxextra declares a floor below that release, so HTML fragments are compared with these tokens flattened.- Return type:
- tests.sphinx.conftest.python_block(*lines)[source]ΒΆ
Build expected Python highlight block.
- Return type: