Skip to content

🧪 Make the MyST-dependent tests pass on MyST-Parser 5.1.0 and master - #310

Merged
chrisjsewell merged 2 commits into
mainfrom
maint/myst-520-test-compat
Nov 9, 2026
Merged

chrisjsewell merged 2 commits into
mainfrom
maint/myst-520-test-compat

Conversation

@chrisjsewell

Copy link
Copy Markdown
Member

What and why

MyST-Parser master (723cffc, the coming 5.2.0) reworks heading anchors (executablebooks/MyST-Parser#1158):
for a heading with an explicit (target)=, the target becomes the section's first (primary) id.
That breaks three sphinx-design tests, although sphinx-design's own output is unchanged:

  • test_snippets.py::test_snippets_myst[html-card-link] and test_snippets_myst_post[html-card-link]:
    the section's ids flip from clickable-cards cards-clickable to cards-clickable clickable-cards.
    The RST and MyST snippets share one fixture, and docutils keeps the old order, so no single fixture fits both.
  • test_badge_tooltips.py::test_ref_badge_tooltip_survives_resolution[html-myst]:
    it counted every href="#my-target" in the page (4 != 2),
    because the theme's headerlink and sidebar TOC now also point at #my-target.

This PR changes tests only:

  1. Badge test: count only the anchors with the sd-badge class that link to #my-target, which is what the assertion is about.
  2. Snippet tests: sort each element's ids before serialising, in all four snippet tests (RST and MyST, pre and post transforms),
    and regenerate the two card-link fixtures. One line changes in each. The full set of ids is still compared; only their order is ignored.

No other fixture changes. Landing this before the MyST-Parser 5.2.0 tag keeps sphinx-design's CI green when 5.2.0 is released
(the testing extra allows myst-parser>=4,<6).

How it was tested

Python 3.13, Sphinx 9.2.0, with pytest tests:

Environment main (before) This branch
myst-parser 5.1.0 from PyPI, docutils 0.22.4 272 passed, 1 skipped 272 passed, 1 skipped
myst-parser master 723cffc (git+https://github.com/executablebooks/MyST-Parser@master), docutils 0.23 3 failed, 269 passed, 1 skipped 272 passed, 1 skipped
testing-no-myst (Python 3.11, Sphinx 9.0.4) not run 182 passed, 91 skipped

The 5.1.0 environment was checked to be the real release (its metadata requires docutils<0.23; master's __version__ is also 5.1.0).

The sorting is needed. With it disabled and the new fixtures kept, tests/test_snippets.py fails on both versions:
on 5.1.0 all four card-link tests fail (2 RST, 2 MyST), and on master the 2 RST card-link tests fail.

pre-commit run --all-files passes.

Notes for the reviewer

  • sort_ids is a local helper in tests/test_snippets.py.
    It is deliberately not part of the semi-public sphinx_design.testing.normalize_doctree_xml,
    so downstream extensions that use that helper do not get churn in their own fixtures.
  • Add link-new-tab flag to card / grid-item-card directives #298 adds a card to the card-link snippets, so its card-link fixtures must be regenerated.
    Doing that on top of this PR records sorted ids, which do not depend on the MyST version.

`test_ref_badge_tooltip_survives_resolution` counted every
`href="#my-target"` in the page. With MyST-Parser master (heading-anchor
rework, executablebooks/MyST-Parser#1158) the explicit `(my-target)=` becomes
the section's primary id, so the theme's headerlink and sidebar TOC also link
to `#my-target` and the count is 4, not 2.

Count only the anchors carrying the `sd-badge` class, which is what the
assertion is about; it holds on MyST-Parser 5.1.0 and on master.
The RST and MyST snippet tests compare against one shared fixture. For a
section with an explicit target, docutils lists the title slug first
(`clickable-cards cards-clickable`), while MyST-Parser master (heading-anchor
rework, executablebooks/MyST-Parser#1158) lists the explicit target first, so
`test_snippets_myst[html-card-link]` and `test_snippets_myst_post[html-card-link]`
fail on master.

The order is a parser detail, not sphinx-design output: sort each element's
ids before serialising, in all four snippet tests, and regenerate the two
card-link fixtures (one line each). The full set of ids is still compared.
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.63%. Comparing base (4f66f32) to head (49a1929).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #310   +/-   ##
=======================================
  Coverage   92.63%   92.63%           
=======================================
  Files          13       13           
  Lines        1371     1371           
=======================================
  Hits         1270     1270           
  Misses        101      101           
Flag Coverage Δ
pytests 92.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chrisjsewell
chrisjsewell merged commit 8771072 into main Nov 9, 2026
26 checks passed
@chrisjsewell
chrisjsewell deleted the maint/myst-520-test-compat branch November 9, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant