Skip to content

Skip Sphinx _build/ output during doctest collection#75

Merged
tony merged 3 commits into
masterfrom
smooth-out-pytest
Jun 27, 2026
Merged

Skip Sphinx _build/ output during doctest collection#75
tony merged 3 commits into
masterfrom
smooth-out-pytest

Conversation

@tony

@tony tony commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix: pytest_doctest_docutils no longer collects Sphinx _build/ output. Built docs mirror their sources — including relative {include} directives that don't resolve from the build tree — so once docs/_build/ existed, collecting those copies aborted the entire test session with a docutils SystemMessage.
  • Root cause: pytest's default norecursedirs excludes build but not _build (the conventional Sphinx output dir). The plugin's *.md/*.rst collection globs then matched the build artifacts.
  • Approach: add a pytest_ignore_collect hook that skips any path with a _build component — 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:

ERROR docs/_build/history.md - docutils.utils.SystemMessage: (SEVERE/4)
Directive "include": file not found: '.../docs/_build/../CHANGES'
!!! Interrupted: 1 error during collection !!!

After — _build/ is ignored and collection proceeds normally.

Design decisions

  • Fix in the plugin, not per-project config: _build/ could be excluded per-repo via norecursedirs or collect_ignore_glob, but this plugin is shared across the git-pull projects and the failure is universal. Handling it once in pytest_ignore_collect fixes every consumer with no config churn — and mirrors how pytest already excludes build by default.
  • Match any _build path component: covers both docs/_build/history.md and the nested docs/_build/html/history.md layout, and skips the directory itself (halting recursion) as well as individual files.

Test plan

  • test_ignore_build_artifacts[build-root] — a docs/_build/history.md with an unresolvable include is skipped while the genuine source doctest still collects
  • test_ignore_build_artifacts[build-html-subdir] — same guarantee for the nested docs/_build/html/ layout
  • Full suite passes with docs/_build/ populated on disk (the reported failure condition)
  • uv run ruff check . and uv run ruff format .
  • uv run mypy src tests
  • uv run py.test
  • just build-docs

Verification

Reproduce the original failure condition and confirm it now passes:

$ just build-docs && uv run py.test

tony added 2 commits June 27, 2026 11:12
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

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.59%. Comparing base (bfd6dd1) to head (27d9736).

Files with missing lines Patch % Lines
src/pytest_doctest_docutils.py 75.00% 1 Missing ⚠️
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.
📢 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.

why: Record the user-facing collection fix for 0.0.18.

what:
- Add "### Fixes" entry for skipping Sphinx _build output
@tony tony force-pushed the smooth-out-pytest branch from 1080499 to 27d9736 Compare June 27, 2026 16:24
@tony tony merged commit 9a1a75b into master Jun 27, 2026
36 checks passed
@tony tony deleted the smooth-out-pytest branch June 27, 2026 16:27
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