On this page
The short answerHow Sybil evaluates a documentWhy documentation examples drift even with SybilSet up the illustrative projectSee what the scan readsMake a shared page easier to scanCatch a real renameRunning both in CITriage findingsWhere DocsAlive fitsThe sources we checkedFAQThe short answer
Run Sybil through pytest to check Python examples in documentation and docstrings as part of the normal test suite. Configure parsers for the document styles you use, make setup and skips deliberate, and inspect the collected results so a skipped region is not mistaken for a passing example.
Engine 0.6.3 of DocsAlive handles Sybil-style pages differently. A python fence containing a >>> session is run as a Python script and becomes an invalid-syntax false positive unless the session is labeled pycon. Invisible setup blocks are unseen, Sybil’s skip and clear-namespace comments are not honored, and Python source docstrings are not read. Use Sybil in pytest for those semantics and a scan for supported page blocks and triage; adapt shared pages deliberately.
How Sybil evaluates a document
Sybil parses examples from code and documentation and evaluates them in the normal test run. It divides each document into non-overlapping regions. Each region becomes an example evaluated in the document’s namespace and in document order. If one example fails, Sybil reports the failure and continues with the remaining examples. Separate documents do not share namespaces.
That model supports a page that introduces a name in one region and uses it later. It also means a later failure may follow an earlier failure: the later region can run without the setup it expected. Read the sequence before deciding that each failure has an independent cause.
Sybil provides pytest and unittest integrations. Its pytest integration uses a conftest.py collection hook, and its documentation recommends disabling pytest’s own doctest plugin. Fixtures can be requested through Sybil’s fixtures argument. The path parameter is ignored with pytest.
For Markdown, use the parsers appropriate to the source: Sybil documents CommonMark, GitHub Flavored Markdown and MyST, with separate MyST parsers. PythonCodeBlockParser checks Python fences, including doctest sessions inside fences labeled python. Invisible Python blocks can live in HTML-style comments. SkipParser supports a next-region skip, a start/end range, conditional skips and reasons; a reason makes an unconditional skip appear as a skipped test. ClearNamespaceParser clears the document namespace at its comment.
Sybil also exposes CodeBlockParser for other languages when you supply an evaluator. A Python parser does not automatically test every shell block on the page. Doctest comparison ignores trailing whitespace by default; Sybil documents NUMBER and KEEP_TRAILING_WHITESPACE option flags for cases that need them.
Why documentation examples drift even with Sybil
Sybil removes the biggest reason Python examples go stale: nobody runs them. Once the examples are pytest items, a rename or a changed return value fails the same build that fails a unit test. What remains are the places where the configuration and the page disagree about what should run.
Collection decides coverage. Sybil only sees files that match its patterns and only checks regions that a configured parser recognizes. A page outside the pattern, a fence label no parser knows, or a docstring in a module the docstring Sybil does not cover is silently out of scope. The test run is green because nothing was asked of those examples.
Setup can hide in comments. Invisible code blocks keep boilerplate out of the reader's way, which is their purpose. They also mean the page a reader copies from is not the page that was tested: the import or variable the visible block depends on lives in a comment the reader never sees.
Skips outlive their reason. A skip with a reason shows up in the test report, which is good practice, but an example skipped for a planned release keeps being skipped after the release unless someone removes the comment. A skip without a reason is reported as a pass in the default report, which is easy to misread.
Order matters inside a document. Regions run in document order in one namespace, so a failure early on a page often causes later failures that are only consequences. The probe below shows exactly that pattern after a rename.
Other languages need their own evaluator. A Python parser does not run the install command or the shell session next to the Python example. Those blocks are untested unless a parser and evaluator are added for them or another tool covers them.
Set up the illustrative project
The following files are illustrative. The package names acme-slug and acme_slug are illustrative and are not published packages. The probe used Sybil 10.1.0, pytest 9.2.0 and Python 3.13.
Install Sybil’s pytest extra and the illustrative package in editable mode in the test environment.
pip install "sybil[pytest]"
pip install -e .
The project configuration disables pytest’s own doctest plugin, following Sybil’s recommendation. The package metadata also gives the example project a small, explicit build configuration.
[project]
name = "acme-slug"
version = "1.0.0"
requires-python = ">=3.10"
[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
packages = ["acme_slug"]
[tool.pytest.ini_options]
addopts = "-p no:doctest"
The illustrative package has doctest examples in a module docstring and a function docstring. Those examples exercise the public import and a function available in the module’s namespace.
"""Make URL slugs from titles.
>>> from acme_slug import slugify
>>> slugify("Hello, World!")
'hello-world'
"""
import re
__all__ = ["slugify", "truncate_slug"]
def slugify(title: str) -> str:
"""Turn a title into a URL slug.
>>> slugify("Release notes: v2.0")
'release-notes-v2-0'
"""
return re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-")
def truncate_slug(slug: str, max_len: int) -> str:
"""Shorten a slug without cutting a word."""
if len(slug) <= max_len:
return slug
cut = slug[: max_len + 1]
return cut[: cut.rfind("-")]
The first conftest.py combines two Sybil instances: one for Markdown and one for docstrings. Their collection becomes one pytest integration. Combining them keeps each parser’s intended scope explicit.
from sybil import Sybil
from sybil.parsers.markdown import ClearNamespaceParser, PythonCodeBlockParser, SkipParser
from sybil.parsers.rest import DocTestParser
markdown_examples = Sybil(
parsers=[PythonCodeBlockParser(), SkipParser(), ClearNamespaceParser()],
patterns=["*.md"],
)
docstring_examples = Sybil(
parsers=[DocTestParser()],
patterns=["acme_slug/*.py"],
)
pytest_collect_file = (markdown_examples + docstring_examples).pytest()
For Python files, Sybil’s Python document imports the source as a module; its Python docstring document considers only docstrings. ReStructuredText and MyST parsers can work with docstrings. Choose patterns and parsers to reflect what your project publishes and tests, rather than assuming a Markdown parser covers source comments.
The first usage page follows a style Sybil supports. Its invisible block supplies setup, its visible Python fences contain both sessions and plain code, and comments control a planned example and a namespace reset.
# Usage
<!-- invisible-code-block: python
from acme_slug import slugify, truncate_slug
long_title = "Testing documentation examples with Sybil"
-->
A python fence can hold a doctest session:
```python
>>> slug = slugify(long_title)
>>> slug
'testing-documentation-examples-with-sybil'
```
Or plain code, which shares the page's namespace:
```python
short = truncate_slug(slug, 20)
assert short == "testing", short
```
<!-- skip: next "ascii_only arrives in 1.1" -->
Planned for the next release:
```python
>>> slugify("Ünïcode", ascii_only=True)
'unicode'
```
<!-- clear-namespace -->
```python
>>> "slug" in globals()
False
```
Run pytest with verbose reporting so the collected examples and the stated skip are visible.
pytest -v
The excerpt shows the usage-page regions and the overall result. The invisible setup is itself tested, and the planned feature appears as a skip with its reason. Across the project, the probe collected twelve items: eleven passed and one was skipped.
docs/usage.md::line:3,column:1 PASSED
docs/usage.md::line:11,column:1 PASSED
docs/usage.md::line:12,column:1 PASSED
docs/usage.md::line:18,column:1 PASSED
docs/usage.md::line:23,column:1 PASSED
docs/usage.md::line:28,column:1 SKIPPED (ascii_only arrives in 1.1)
docs/usage.md::line:32,column:1 PASSED
docs/usage.md::line:35,column:1 PASSED
======================== 11 passed, 1 skipped in 0.01s =========================
The configured Sybil parsers did not check the README’s shell fence. That is a scope decision, not a failure of the Python examples. Inventory the languages on each page and add an appropriate evaluator or another check for the blocks that matter.
See what the scan reads
The following command plans a scan; it does not itself execute the examples.
docsalive scan .
The plain-project plan found two pages and six blocks in docs/ plus the root README. In a separate engine-driver run with the package installed and the network off, the README install line was skipped and its Python block passed. Three Python fences containing sessions failed as invalid-syntax: the engine tried to run the prompts as a script. Those were false positives counted in a docs-bug category.
The plain Python block failed as depends-on-context because the import it needed was inside the invisible comment. The engine skipped that multiline comment. It also did not read the docstrings in the Python file. These differences are about how the two tools interpret the source, so a result from one should not be presented as coverage supplied by the other.
| Sybil feature | What Sybil does | What the engine does in 0.6.3 |
|---|---|---|
Session in a python fence |
Parses and evaluates the doctest session | Runs the fence as a script; prompts cause an invalid-syntax false positive |
| Invisible setup | Evaluates the configured invisible Python block | Skips the multiline HTML comment |
| Skip comment | Skips the selected region; a reason can appear in results | Does not honor the comment |
| Clear-namespace comment | Clears the document namespace | Does not honor the comment |
| Python docstring | Can collect examples with a suitable document and parser | Does not read docstrings in .py files |
| Other language | Can evaluate it with CodeBlockParser and a custom evaluator |
Handles supported fence types according to its own planner |
| Document state | Evaluates regions in order in one document namespace | Python blocks share a page namespace; separate pages start fresh |
Make a shared page easier to scan
A pycon label tells the engine that a fence contains a session. The following verified subclass lets Sybil 10.1.0 check that label in the same way as its Python fences. The file is illustrative and should be tested in your own project.
from sybil import Sybil
from sybil.evaluators.python import PythonEvaluator
from sybil.parsers.markdown import (
ClearNamespaceParser,
CodeBlockParser,
PythonCodeBlockParser,
SkipParser,
)
from sybil.parsers.rest import DocTestParser
class PyconCodeBlockParser(PythonCodeBlockParser):
"""Check pycon fences the same way Sybil checks python fences."""
def __init__(self) -> None:
super().__init__()
self.codeblock_parser = CodeBlockParser("pycon", PythonEvaluator())
markdown_examples = Sybil(
parsers=[
PythonCodeBlockParser(),
PyconCodeBlockParser(),
SkipParser(),
ClearNamespaceParser(),
],
patterns=["*.md"],
)
docstring_examples = Sybil(
parsers=[DocTestParser()],
patterns=["acme_slug/*.py"],
)
pytest_collect_file = (markdown_examples + docstring_examples).pytest()
This subclass sets codeblock_parser, an attribute Sybil 10.1.0 uses internally rather than a documented option. Pin the Sybil version and rerun the tests after an upgrade. Treat the subclass as project code that needs maintenance, not as a guarantee about future Sybil releases.
The following illustrative change labels sessions pycon and moves setup into the first visible session. It leaves the skip and namespace comments in place so their different interpretation remains visible.
@@ -1,19 +1,15 @@
# Usage
-<!-- invisible-code-block: python
-from acme_slug import slugify, truncate_slug
-long_title = "Testing documentation examples with Sybil"
--->
+A pycon fence holds a doctest session:
-A python fence can hold a doctest session:
-
-```python
->>> slug = slugify(long_title)
+```pycon
+>>> from acme_slug import slugify, truncate_slug
+>>> slug = slugify("Testing documentation examples with Sybil")
>>> slug
'testing-documentation-examples-with-sybil'
```
-Or plain code, which shares the page's namespace:
+Plain code in a python fence shares the page's namespace:
```python
short = truncate_slug(slug, 20)
@@ -24,14 +20,14 @@
Planned for the next release:
-```python
+```pycon
>>> slugify("Ünïcode", ascii_only=True)
'unicode'
```
<!-- clear-namespace -->
-```python
+```pycon
>>> "slug" in globals()
False
```
Run pytest again and plan the scan again. For execution, install the package in the scan environment and use the relevant execution options from the CLI reference.
pytest -v
docsalive scan .
Pytest again produced eleven passes and one skip. In the engine-driver probe, the first session passed and the plain Python block passed. The engine compares printed output only in Python pycon (>>>) sessions, which is why the session label matters.
Two mismatches remained. The engine ignored the skip comment and ran the planned-feature session, producing an api-drift finding counted as a likely docs bug. It also ignored the clear-namespace comment, so the final session produced a warning for differing printed output. Both were false results for this repository’s intended Sybil semantics.
Keep planned features out of scanned current-version pages, or use --include to select pages that are suitable for the scan. A visible setup block helps both the reader and the scanner, but it does not make Sybil’s control comments meaningful to the engine.
Catch a real rename
The following change is broken on purpose. It renames the public function and leaves the documentation unchanged.
-__all__ = ["slugify", "truncate_slug"]
+__all__ = ["slugify", "shorten_slug"]
@@
-def truncate_slug(slug: str, max_len: int) -> str:
+def shorten_slug(slug: str, max_len: int) -> str:
Pytest reported two failures, nine passes and one skip. The first failed import also explains why the later region lacked the function; Sybil continued and reported that later failure too.
FAILED docs/usage.md::line:6,column:1
ImportError: cannot import name 'truncate_slug' from 'acme_slug'
FAILED docs/usage.md::line:14,column:1 - NameError: name 'truncate_slug' is not defined
2 failed, 9 passed, 1 skipped
In the scan probe, the first session failed as api-drift, while the later Python block was classified as depends-on-context. Fix the public API or update the page according to the intended release, then rerun both checks. The Python documentation testing guide covers broader Python setup and execution choices.
Running both in CI
A workable split, offered as advice rather than a rule, keeps each tool on the job it does well.
- Run pytest with Sybil on every pull request. It is fast, it runs in the same environment as the unit tests, and it covers docstrings and the control comments the page author chose.
- Run the scan in CI as well, or on a schedule, so the pages are executed in a clean sandbox where only the documented install steps and the setup you pass with the scan are present. That catches an import that works on a developer machine only because the package is already installed. The GitHub Actions guide shows where such a job fits.
- Keep one labeling convention for doctest sessions in Markdown, the pycon label with the parser subclass above, so the two tools agree on what a block is.
- Decide page by page whether invisible setup is acceptable. On pages that are also scanned, prefer a short visible setup block; readers benefit from seeing the import too.
- Review skipped and not-judged results as part of the release checklist rather than treating a green run as full coverage. The docs testing checklist has a release-time list.
Triage findings
| Finding | Likely cause | What to do |
|---|---|---|
invalid-syntax on a session |
Prompts are in a python fence that the engine runs as a script |
Use pycon for shared pages and configure Sybil to evaluate it |
| Missing name after invisible setup | The engine did not read the comment | Put reader-relevant setup in a visible first block |
| Planned API reported as drift | The engine did not honor a Sybil skip | Keep the planned example out of scanned pages or select another scope |
| Namespace result differs | The engine did not clear state at the comment | Interpret the warning in light of Sybil’s separate semantics |
| A later Sybil region fails after an earlier one | Required state was not created because the earlier example failed | Fix and rerun from the first failure |
| Docstring change is absent from the scan | Source docstrings are outside the engine’s page selection | Keep docstring collection in Sybil |
| Shell instructions lack Sybil coverage | No evaluator was configured for them | Add an appropriate check and record its scope |
Where DocsAlive fits
Run Sybil in pytest locally and in CI for Python examples, document ordering, docstrings and the configured control comments. Use DocsAlive alongside it for clean-sandbox runs of supported page blocks, other supported block types and categorized findings. A fresh page environment can reveal an undeclared dependency, but setup supplied to the scan should still be compared with the instructions a reader sees.
The engine reads .md, .mdx and .markdown pages. In a plain project with a top-level docs/ directory, its default scope is that directory plus the root README. It does not read source-file docstrings. See framework support and finding categories when deciding what a report establishes.
For projects that publish through Sphinx or pdoc, see the Sphinx guide and pdoc guide. The pre-commit guide covers placing fast checks close to an edit. For lighter Markdown-only runners, see phmdoctest and pytest-markdown-docs.
Sybil documentation test checklist
[ ] Install the project and Sybil's pytest integration in the test environment.
[ ] Disable pytest's own doctest plugin as Sybil recommends.
[ ] Select the right parsers and document patterns.
[ ] Collect Markdown examples and source docstrings deliberately.
[ ] Review the order and namespace dependencies within each document.
[ ] Give unconditional skips a reason and review planned features.
[ ] Label shared doctest sessions pycon and test the compatibility parser.
[ ] Keep reader-relevant setup visible when the page is also scanned.
[ ] Remember that the scan ignores Sybil skip and clear-namespace comments.
[ ] Run pytest and the scan, then review skips and findings in context.
The sources we checked
These sources were read on November 15, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| Sybil documentation | The project and supported integrations |
| Using Sybil | Configuring a documentation test run |
| Sybil Markdown parsers | Code blocks, invisible setup, skips and namespace controls |
| Sybil integrations | pytest and unittest integration |
| Sybil concepts | Documents, regions, examples and namespaces |
| Sybil API | Configuration and parser interfaces |
| Python doctest | Interactive examples and expected printed results |
FAQ
What does Sybil test?
Sybil parses examples from configured documents and code, then evaluates them as part of a test run. Its behavior depends on the document types, patterns and parsers you configure.
How does DocsAlive handle Sybil-style pages?
Engine 0.6.3 treats a python fence containing prompts as a script, causing an invalid-syntax false positive unless the session is labeled pycon. It does not see invisible blocks, honor skip or clear-namespace comments, or read source docstrings.
Do Sybil examples share state?
Examples in one document run in document order in that document's namespace. Separate documents do not share a namespace. Sybil reports a failure and continues with remaining examples.
Why disable pytest's doctest plugin?
Sybil's pytest documentation recommends disabling it when using Sybil's integration. Configure collection deliberately so the intended tool evaluates each example.
Can both tools check a pycon fence?
Yes, with the illustrated Sybil 10.1.0 subclass and a pycon label. The subclass relies on an internal attribute, so pin Sybil and rerun the tests after upgrades.
Does a Sybil skip also skip a scan?
No. The engine does not honor that comment in 0.6.3. Keep planned examples out of scanned pages or use page selection, and review remaining mismatches.




