Skip to content

Fix tests for Docutils 0.22+ #13549

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, cast

import docutils
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.misc import Class
Expand All @@ -21,14 +22,15 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any, ClassVar
from typing import Any, ClassVar, Final

from docutils.nodes import Element, Node

from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata, OptionSpec


DU_22_PLUS: Final = docutils.__version_info__ >= (0, 22, 0, 'alpha', 0)
glob_re = re.compile(r'.*[*?\[].*')
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -330,6 +332,14 @@ def run(self) -> list[Node]:
surrounding_section_level = memo.section_level
memo.title_styles = []
memo.section_level = 0
if DU_22_PLUS:
# https://github.com/sphinx-doc/sphinx/issues/13539
# https://sourceforge.net/p/docutils/code/10093/
# https://sourceforge.net/p/docutils/patches/213/
surrounding_section_parents = memo.section_parents
memo.section_parents = []
else:
surrounding_section_parents = []
try:
self.state.nested_parse(
self.content, self.content_offset, node, match_titles=True
Expand Down Expand Up @@ -365,6 +375,8 @@ def run(self) -> list[Node]:
return []
finally:
memo.title_styles = surrounding_title_styles
if DU_22_PLUS:
memo.section_parents = surrounding_section_parents
memo.section_level = surrounding_section_level


Expand Down
7 changes: 0 additions & 7 deletions tests/test_directives/test_directive_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
import re
from typing import TYPE_CHECKING

import docutils
import pytest
from docutils import nodes

if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp

xfail_du_22 = pytest.mark.xfail(
docutils.__version_info__ >= (0, 22, 0, 'alpha', 0),
reason='expected failure on Docutils 0.22+',
)


@xfail_du_22
@pytest.mark.sphinx('text', testroot='directive-only')
def test_sectioning(app: SphinxTestApp) -> None:
def getsects(section):
Expand Down
9 changes: 0 additions & 9 deletions tests/test_environment/test_environment_toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import TYPE_CHECKING

import docutils
import pytest
from docutils import nodes
from docutils.nodes import bullet_list, list_item, literal, reference, title
Expand All @@ -18,13 +17,7 @@
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp

xfail_du_22 = pytest.mark.xfail(
docutils.__version_info__ >= (0, 22, 0, 'alpha', 0),
reason='expected failure on Docutils 0.22+',
)


@xfail_du_22
@pytest.mark.sphinx('xml', testroot='toctree')
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
def test_process_doc(app):
Expand Down Expand Up @@ -471,7 +464,6 @@ def test_domain_objects_document_scoping(app: SphinxTestApp) -> None:
)


@xfail_du_22
@pytest.mark.sphinx('xml', testroot='toctree')
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
def test_document_toc(app):
Expand Down Expand Up @@ -529,7 +521,6 @@ def test_document_toc(app):
assert_node(toctree[2][0], [compact_paragraph, reference, 'Indices and tables'])


@xfail_du_22
@pytest.mark.sphinx('xml', testroot='toctree')
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
def test_document_toc_only(app):
Expand Down
Loading