On this page
The short answerWhat pdoc publishesWhy pdoc examples break or go untestedBuild the illustrative packageRun the prompted examplesUnderstand the engine's source scanCreate a scan-ready copy of public docstringsTriage the resultWhere DocsAlive fitsThe sources we checkedFAQThe short answer
Use doctest for prompted Python sessions and a separate scan-ready copy for fenced docstring examples. pdoc can publish both, but doctest collects examples by their >>> prompts and does not collect ordinary fenced Python examples. Engine 0.6.3 does not detect pdoc or scan .py files, so DocsAlive reads the README as plain Markdown but never sees the docstrings. In the probe, it scanned the README session; if present, .pytest_cache/README.md was also listed as a page.
Run pytest --doctest-modules for prompted docstring examples and --doctest-glob for prompted examples in Markdown. Then generate a scan-ready copy of the public docstrings for fenced examples and triage. This split gives each tool a clear job and makes its blind spots visible. It does not replace a pdoc build or a review of the generated reference.
The walkthrough uses pdoc 16.0.0 and engine 0.6.3. It includes an illustrative package, a README fence trap, and a deliberately broken API call. For broader context, see Python docs testing and API reference docs testing.
What pdoc publishes
pdoc interprets docstrings as Markdown using markdown2, including support for fenced code blocks and pyshell, which treats unindented Python interactive sessions as code blocks. Its docformat can be set with a command option or __docformat__: markdown, restructuredtext, google, and numpy are available. The default is restructuredtext, which processes reStructuredText elements before Markdown.
An external Markdown file can be included with the reStructuredText include directive. Including a README from the top-level package's __init__.py is a common pattern. The directive supports selecting lines or boundaries, so the published text may be only part of the file. pdoc only outputs HTML, so anything you test has to come from the source files or from a copy you generate.
The public API is another selection boundary. If a module defines __all__, pdoc treats only the listed identifiers as public. Otherwise, public items are those defined in the module whose names do not start with an underscore. A docstring's @private can hide an item, while @public can show one. Specifying __all__ is the recommended way to exclude submodules.
A test run can therefore cover a different set of examples from the generated reference. A private helper can be tested by doctest even though pdoc does not publish it. Conversely, a fenced example can appear in the HTML while doctest never collects it.
Why pdoc examples break or go untested
pdoc makes it easy to keep reference text next to the code it describes, which is a good reason to use it. The same design creates a few predictable gaps.
The two example forms are checked by different tools. A bare >>> session in a docstring is something doctest can run. A fenced Python example in the same docstring is displayed by pdoc but never collected by doctest, because doctest looks for prompts, not fences. A project can have a fully green doctest run while every fenced example in its reference is stale.
What doctest runs and what pdoc publishes are different sets. Doctest runs every prompted docstring it collects, including those of private helpers that pdoc leaves out. pdoc publishes public items chosen by __all__ and underscore privacy. A green doctest run can therefore include examples no reader ever sees, and miss examples every reader sees.
The README is read twice. It is often included in the top-level module docstring and also published on its own. If it is tested with doctest as a text file, Markdown fence lines can collide with doctest's rule for where expected output ends.
Docstrings are not Markdown files. A tool that scans .md files, including engine 0.6.3, never reads a .py file, so docstring examples are invisible to it unless you generate a copy.
Finally, a successful pdoc build is not an execution check. pdoc renders whatever the docstring says, including a call with an argument the function no longer accepts.
Build the illustrative package
Set up the environment and install the local package for the walkthrough:
python3 -m venv .venv
. .venv/bin/activate
pip install pdoc pytest
pip install -e .
A clean environment makes the package under test explicit. For a real project, record the interpreter, package artifact, and dependencies used by CI so a reviewer can reproduce a failure. Installation from a checkout answers a different question from installation of a released artifact.
The following illustrative project metadata defines the package:
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "acme-client"
version = "2.4.1"
requires-python = ">=3.10"
[tool.setuptools]
packages = ["acme"]
The package's top-level docstring includes the README, and its public list names two functions:
"""
.. include:: ../README.md
"""
from .version import parse_version, connect
__all__ = ["parse_version", "connect"]
The include lets the reference reuse the README. It also means that the same text can be encountered through more than one path: directly as Markdown and as included module documentation. Keep track of which check covers which copy so a report does not imply more independent coverage than it has.
The next illustrative file contains the two example forms and a private helper:
"""Version helpers for the acme client."""
def parse_version(text: str) -> tuple[int, ...]:
"""Split a release string into integers.
>>> parse_version("2.4.1")
(2, 4, 1)
"""
return tuple(int(part) for part in text.split("."))
def connect(host: str, port: int = 8080) -> str:
"""Build the address the client connects to.
```python
from acme import connect
print(connect("localhost"))
```
"""
return f"{host}:{port}"
def _retry_delay(attempt: int) -> float:
"""Private helper; pdoc leaves it out.
>>> _retry_delay(3)
4.0
"""
return 0.5 * 2 ** attempt
The prompted session in parse_version is recognizable to doctest. The fenced example in connect is readable to pdoc and to a Markdown fence extractor once it is available in a Markdown page, but doctest does not collect it as an ordinary fenced Python example. The private helper has a prompted session that doctest can run even though pdoc leaves the helper out.
The README starts with a fenced interactive session. This first form is illustrative and is deliberately arranged to expose a doctest parsing problem:
# acme-client
Parse a release string:
```pycon
>>> from acme import parse_version
>>> parse_version("2.4.1")
(2, 4, 1)
```
Build the HTML reference:
pdoc acme -o html
The probe produced one module page, html/acme.html. It showed the included README session, the bare prompted example, and the fenced example. The acme.version submodule had no page of its own because the public list contained only the two functions, and the underscore-prefixed helper was omitted.
A successful pdoc build shows that pdoc could generate the reference under that configuration. It does not establish that each example ran or that every published call still matches the implementation. Check the HTML when changing public visibility or include boundaries, then run the examples separately.
Run the prompted examples
Use pytest's doctest collection for module docstrings:
python -m pytest --doctest-modules acme
The probe reported two passing examples: parse_version and the private _retry_delay. The fenced connect example was not collected. This is a useful result, but its scope is specific: it verifies the collected prompted sessions under the test environment, including one session that pdoc did not publish.
Run the README session as a text-file doctest too:
python -m pytest --doctest-glob="README.md" README.md
The first README form failed. The recorded failure illustrates what doctest treated as expected output:
Expected:
(2, 4, 1)
```
Got:
(2, 4, 1)
Doctest finds examples by the prompts and reads expected output until a blank line or the next prompt. With the closing fence directly after the displayed result, that fence became part of the expected output. The failure is about the boundary between Markdown markup and doctest's text parser, not necessarily about the function.
The tested fix adds a blank line before the closing fence:
(2, 4, 1)
+
```
After that change, the same README doctest passed and pdoc still rendered the session. When applying this pattern, check both consumers: the text-file doctest must stop at the intended boundary, and the generated HTML should still show the example as intended.
Understand the engine's source scan
The next command plans a source scan with package setup for each page:
docsalive scan . --setup "pip install -e ."
The default CLI invocation only plans the run. In the probe, the engine treated the project as plain Markdown and scanned from the repository root. Without the pytest cache it collected one page, the README, and one block. With .pytest_cache present, its README was also listed as a second page, although it contained no code blocks.
When run with the package installed, the README session passed in both fence forms. Only pycon (>>>) sessions have their printed output compared by the engine; nothing else is compared. No docstring in the Python files was read. The README result therefore says nothing about the fenced example inside connect.
| pdoc item | What pdoc does | What the engine does in 0.6.3 |
|---|---|---|
| Module and member docstrings | Converts selected docstrings into HTML documentation | Never scans .py files as pages |
| Bare prompted session | Displays it as code through pyshell |
Does not see it inside a docstring |
| Fenced Python docstring example | Displays the fenced example | Does not see it inside a docstring |
| Included README | Can include selected external Markdown in a docstring | Scans a collected README as a separate Markdown page; does not expand the directive |
__all__ and privacy markers |
Select public documentation | Does not apply pdoc's public API model to source files |
| Pytest cache README | Is not the intended API reference | Can list it as a page during a root scan |
| Generated HTML | Publishes the reference | Is not a scanned Markdown page |
The collector reads .md, .mdx, and .markdown files. It skips certain named folders, but other hidden folders can be collected. If a top-level docs/ folder exists, the plain-project default is that folder plus the root README when present. An include filter only filters collected pages; it cannot add pages from a skipped folder.
Create a scan-ready copy of public docstrings
The following illustrative script uses pdoc's module model. It writes public docstrings to Markdown, wraps bare prompted sessions in fences, drops include directive lines, and skips docstrings containing @private.
"""Write the docstrings pdoc publishes to Markdown files that a docs scan can read."""
import re
import sys
import textwrap
from pathlib import Path
import pdoc.doc
PROMPT = re.compile(r"^>>> ")
def fence_sessions(text, setup=None):
"""Wrap bare >>> sessions (pdoc shows them as code) in pycon fences."""
out, in_fence, in_session = [], False, False
for line in text.split("\n"):
if line.startswith("```"):
in_fence = not in_fence
if not in_fence and not in_session and PROMPT.match(line):
out.append("```pycon")
if setup:
out.append(setup) # doctest runs docstrings with the module's names
in_session = True
elif in_session and not line.strip():
out.append("```")
in_session = False
out.append(line)
if in_session:
out.append("```")
return "\n".join(out)
def page_for(module):
parts = [f"# {module.modulename}", ""]
doc = re.sub(r"^\.\. include::.*$", "", module.docstring, flags=re.M).strip()
if doc:
parts += [fence_sessions(doc), ""]
for member in module.members.values():
text = textwrap.dedent(member.docstring).strip()
if not text or "@private" in text:
continue
setup = f">>> from {module.modulename} import *"
parts += [f"## {member.qualname}", "", fence_sessions(text, setup), ""]
return "\n".join(parts)
out = Path(sys.argv[2])
for name in sys.argv[1].split(","):
module = pdoc.doc.Module.from_name(name)
for mod in [module, *module.submodules]:
target = out / "api" / f"{mod.modulename}.md"
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(page_for(mod))
print(f"wrote {target}")
Using pdoc's own model aligns the basic module and member selection with what pdoc documents, including __all__ and underscore privacy. The generated files are a test representation, so inspect them when changing the package's documentation structure.
Generate the copy and plan a scan:
python tools/pdoc_scan_copy.py acme scan-docs
docsalive scan . --docs-dir scan-docs --setup "pip install -e ."
The recorded script output was:
wrote scan-docs/api/acme.md
The scan collected two pages: the root README, which the engine adds, and the generated API page. It extracted three blocks; when run, all three passed. The copy made the fenced docstring example available to the engine while retaining the README as its own page.
The script has important limits. Its star import brings in only names exported by the module; underscore names and names outside __all__ can still produce depends-on-context. It drops include directives instead of expanding them, so an included file other than the root README is not scanned through this copy. It does not apply reStructuredText, Google, or numpy docstring conversion.
It covers the module and submodules pdoc lists, but not class members' nested docstrings beyond what the module's members list provides. Private docstrings are not scanned, although doctest can still run them. Maintain an inventory of these gaps, especially if your published reference relies on nested members or included files.
The selected scan directory should also avoid a docs/ subfolder: in engine 0.6.3, that layout causes the scan to narrow to that subfolder. Regenerate the copy in CI so it reflects the checked-out code and public API.
Demonstrate the fenced-example gap
The following change is broken on purpose: the illustrative function does not accept the added argument.
- print(connect("localhost"))
+ print(connect("localhost", timeout=5))
pdoc still built the reference, and the module doctest run still reported two passes because it did not collect the fenced example. When the scan-ready copy was run, the block failed as api-drift because the current API did not accept the argument.
This is the reason for the split. Doctest provides a direct check of prompted sessions, including expected values. The copy exposes fenced examples and gives triage a chance to identify a changed API. The pdoc build and HTML review establish what readers see. Each result covers a different boundary.
Triage the result
| Finding | Likely cause | What to do |
|---|---|---|
| README doctest expects a closing fence | No blank line separated the expected value from Markdown markup | Add the boundary and rebuild the HTML |
| A private helper's doctest fails | Doctest collected a docstring pdoc does not publish | Fix or maintain the private test, and label it separately from published reference coverage |
| A fenced call is absent from doctest results | It has no prompted session for doctest to collect | Scan or test the fenced example separately |
A generated session reports depends-on-context |
Its name was not imported by the copy's setup | Review public exports and add an appropriate independent test where needed |
A public call fails as api-drift |
An import, attribute, or argument no longer matches the installed API | Reproduce against the intended package version and update the example or API |
| A page count changes after pytest | A cache README was collected | Inspect the page inventory before comparing counts |
| An included file is missing from the copy | The script drops include directives | Add a separate check for that file and inspect the generated reference |
Do not treat every failure as the same kind of documentation defect. A missing fixture, missing tool, or name supplied elsewhere can need a different response from a call that no longer matches the public API. Likewise, an unfamiliar fence label can be reported as passing without execution or parsing in engine 0.6.3; confirm checker support before relying on it.
Use this checklist for a change to the package or reference:
[ ] Record the package version and environment used for the reference build.
[ ] Build pdoc and inspect public items, included content, and example formatting.
[ ] Run prompted module examples with pytest doctest collection.
[ ] Run prompted Markdown examples with the intended doctest glob.
[ ] Check blank-line boundaries before closing fences in text-file doctests.
[ ] Generate the scan-ready copy from the current public module model.
[ ] Scan fenced examples with the package setup required by the page.
[ ] Review private, nested, and externally included docstrings outside the copy's coverage.
[ ] Triage failures and skips against the version readers will use.
Where DocsAlive fits
DocsAlive can extract supported fences from the generated Markdown copy, run examples in page order, and classify findings. It does not render pdoc or read the original Python files in engine 0.6.3. The copy is a bridge for the examples it covers, not a claim that all generated HTML has been tested.
Use the CLI reference to choose scan scope and setup, and the findings reference to interpret categories. Every plan runs the scan on a schedule, and the Team plan and above add pull request checks and draft fix pull requests; pricing lists what each plan includes. To see a real report on a public repository you maintain, use the health check. For another Python documentation workflow, see Sphinx docs testing. The analogous source-to-page boundary appears in Hexo and Doxygen projects, although their source formats and checks differ.
The sources we checked
The following sources were read on November 14, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| pdoc documentation | Docstring formats, Markdown, includes, public API selection, and HTML output |
| Python doctest documentation | Prompted sessions and expected-output boundaries |
| pytest doctest guide | Module and text-file doctest collection |
FAQ
Does DocsAlive detect pdoc or scan docstrings?
Engine 0.6.3 does neither: it treats the project as plain Markdown and never scans Python files as pages. It scans a collected README, including supported pycon sessions, and can list the pytest cache README as another page.
Does doctest run fenced Python examples?
Doctest collects prompted sessions marked with the Python interactive prompt. An ordinary fenced Python example without those prompts needs a separate check.
Why can a private helper pass doctest but be absent from pdoc?
The tools select content differently. Doctest can run a prompted session in a private helper's docstring, while pdoc can omit that helper from the published reference.
Why did the README doctest include the closing fence?
Without a blank line after the expected value, doctest read the fence as another expected-output line. The tested blank-line change gave doctest a boundary while preserving the rendered session.
Does the scan-ready copy cover every pdoc page?
No. It has the stated limits around included files, docformat conversion, nested class members, private docstrings, and names outside public exports. Inspect the generated reference and maintain separate checks for those gaps.
What should run in CI?
Build the reference, run module doctests and the relevant Markdown doctest glob, regenerate and scan the public docstring copy, and review failures and uncovered examples against the intended package version.




