Skip to content

test(docs): Run plain Python and console fences - #219

Merged
tony merged 1 commit into
masterfrom
docs-codeblocks
Dec 6, 2026
Merged

tony merged 1 commit into
masterfrom
docs-codeblocks

Conversation

@tony

@tony tony commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #217

1. Owner and boundary

  • Rule changed and module that owns it: Markdown code-block collection and execution for README.md and docs/**/*.md now live in tests/_docs_codeblocks.py, wired via pytest_collect_file in root conftest.py and marked documentation in pyproject.toml. Keeping the harness under tests/ preserves dependencies = [], side-effect-free import libvt, lazy pytest11 discovery, sdist inclusion, and a libvt-only wheel.
  • Sibling entry points checked (sync/async, CLI/API, single/batch, or N/A): Checked pytest_doctest_docutils (gp-libs) coexistence so >>> doctests keep running without double execution, tests/test_libvt.py (test_markdown_code_fences_are_collected_and_classified, test_documented_examples_include_explicit_imports), MIGRATION historical # Before / # After blocks, {literalinclude} directives, vt_snapshot two-pass --snapshot-update + deterministic .ambr match when syrupy is active (skipping cleanly when absent), unpacked sdist layouts without scripts//justfile/.git, and docs/api/pytest_plugin.md + docs/quickstart.md plain python fixture blocks.
  • Why this belongs here (owner fix, boundary adapter, or single-PR ownership transfer): Repo-local test harness belonging under tests/ and root conftest.py; VT emulation semantics are unchanged so VT byte-replay comparisons in REVIEW.md section 2 are inapplicable.

2. Failure before the fix (N/A for docs, lockfile bumps, or pure refactors)

  • Baseline (<base> commit, or <pre_fix_head> SHA if fixing a defect introduced in this PR): b77d7e4 (master).
  • Failing input or command and observed failure before the fix: On b77d7e4, adding a plain python fence without >>> prompts was rejected by test_markdown_python_fences_carry_doctest_prompts rather than executed, and none of the 30 console fences or 6 {literalinclude} directives across README.md and docs/ ran under pytest. After adding the harness, negative controls confirmed failures on a broken plain python fence in README.md, a broken plain python fence in docs/quickstart.md, a broken runnable console fence in docs/topics/interactive-game.md, an unclassified console fence in docs/quickstart.md, trailing plain-Python lines after doctests, --record and .//// path-normalization sandbox escapes, non-read-only scripts, recursive/multi--m pytest targets, POSIX octal printf escapes, symlinked TMPDIR fallbacks, non-deterministic and unused vt_snapshot blocks, replay output mismatches, and disabling the unclassified-fence guard in tests/_docs_codeblocks.py.

3. Verification and tool disclosure

  • Gates run (plus production-only revert check for behavioral fixes, or N/A): uv run ruff check ., uv run ruff format --check ., uv run ty check across Python 3.12–3.15 and --python-version 3.12 --python-platform win32, PYTHONDONTWRITEBYTECODE=1 uv run python -B scripts/check_workarounds.py, uv run pytest -m documentation (41 passed), uv run pytest -m "" (1410 passed, 3 skipped), uv run sphinx-build -W -b dirhtml -d docs/_build/doctrees docs docs/_build/html, and uv build wheel cleanliness (48 libvt-only entries) plus unpacked-sdist verification (37 passed, 4 skipped on -m documentation README.md docs and 12 passed on tests/test_docs_codeblocks.py).
  • .github/workarounds.toml updates (None if none): None.
  • Tool use: git, gh, uv, ruff, ty, pytest, sphinx-build.

why: Verify copy-pasteable Python blocks, runnable console commands,
and MyST literalinclude directives across README.md and docs/ in
pytest and CI alongside existing doctests.

what:
- Add tests/_docs_codeblocks.py and wire conftest.py pytest_collect_file
- Register pytest documentation marker and allow exec in docs harness
- Execute plain python fences in isolation (UTF-8, explicit imports,
  sandboxed tempfile.tempdir) and run uncalled test_* functions and
  Test* classes via real pytest fixtures
- Parse CommonMark 4.5 and MyST code-block/colon directives, enforce
  strict doctest vs plain-python separation, and fail CI on
  unclassified or trailing-line console blocks and recursive pytest
- Keep unpacked sdists passing when scripts/justfile/.git are absent
  and keep the harness out of wheels and pytest11 entry points
- Convert pytest_plugin and quickstart fixture blocks to plain python,
  classify MIGRATION Before/After blocks, add negative-control tests,
  and update WRITING.md, CONTRIBUTING.md, and CHANGES
@tony
tony merged commit b0087a2 into master Dec 6, 2026
10 checks passed
@tony
tony deleted the docs-codeblocks branch December 6, 2026 02:09

This branch was successfully deployed

1 active deployment
docs — 3f916586 Deployed Dec 6, 2026 by tony via build (3.14) #549
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.

Test plain python and console Markdown code blocks in pytest

1 participant