Documentation test policy¶
Every Python example published in the documentation must execute unchanged as
part of the automated test suite. The maintainer workflow mirrors the directory
structure under docs/ so each page with a python code block has a matching
module under tests/docs/.
Principles¶
Copy code verbatim. Tests for documentation examples should copy the code blocks directly from the source page. Avoid rewriting the snippet so the exercises remain faithful to what readers run locally.
Mirror the docs hierarchy. Place tests in
tests/docs/<path-to-page>so the file tree matches the documentation layout. This keeps navigation obvious when auditing coverage.Cover the README. The README quickstart follows the same rule—create a
tests/test_readme_doc.pymodule unless a quickstart test already exercises the identical snippet.Gracefully skip optional extras. When examples rely on optional dependencies (
prometheus_client, PlotSpec, pandas, etc.), guard the test withpytest.importorskipso missing extras do not break baseline CI runs.
Maintainer checklist¶
Add or update the corresponding test whenever a documentation snippet changes.
Update
docs/foundations/governance/test_policywhen the strategy for organising documentation tests evolves.Confirm
pytest tests/docsruns cleanly before promoting changes that touch docs or README examples.