Skip Sphinx _build/ output during doctest collection#75
Merged
Conversation
why: pytest's default norecursedirs excludes "build" but not
"_build", so Sphinx output was collected once docs/_build/ existed.
Those copies keep relative {include} directives that no longer
resolve, aborting collection with a docutils SystemMessage.
what:
- Add pytest_ignore_collect hook skipping any path under _build/
why: Guard against regressions where Sphinx build artifacts under _build/ get collected and abort the session. what: - Add parametrized pytester test for docs/_build/ and docs/_build/html/ layouts
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #75 +/- ##
==========================================
+ Coverage 73.08% 73.59% +0.51%
==========================================
Files 14 14
Lines 836 856 +20
==========================================
+ Hits 611 630 +19
- Misses 225 226 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
why: Record the user-facing collection fix for 0.0.18. what: - Add "### Fixes" entry for skipping Sphinx _build output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pytest_doctest_docutilsno longer collects Sphinx_build/output. Built docs mirror their sources — including relative{include}directives that don't resolve from the build tree — so oncedocs/_build/existed, collecting those copies aborted the entire test session with a docutilsSystemMessage.norecursedirsexcludesbuildbut not_build(the conventional Sphinx output dir). The plugin's*.md/*.rstcollection globs then matched the build artifacts.pytest_ignore_collecthook that skips any path with a_buildcomponent — stopping both directory recursion and file collection, so every consumer is fixed with no per-project config.Behavior
Before — with
docs/_build/present, collection aborts:After —
_build/is ignored and collection proceeds normally.Design decisions
_build/could be excluded per-repo vianorecursedirsorcollect_ignore_glob, but this plugin is shared across the git-pull projects and the failure is universal. Handling it once inpytest_ignore_collectfixes every consumer with no config churn — and mirrors how pytest already excludesbuildby default._buildpath component: covers bothdocs/_build/history.mdand the nesteddocs/_build/html/history.mdlayout, and skips the directory itself (halting recursion) as well as individual files.Test plan
test_ignore_build_artifacts[build-root]— adocs/_build/history.mdwith an unresolvable include is skipped while the genuine source doctest still collectstest_ignore_build_artifacts[build-html-subdir]— same guarantee for the nesteddocs/_build/html/layoutdocs/_build/populated on disk (the reported failure condition)uv run ruff check .anduv run ruff format .uv run mypy src testsuv run py.testjust build-docsVerification
Reproduce the original failure condition and confirm it now passes:
$ just build-docs && uv run py.test