On this page
The short answerWhat the plugin collectsWhy blocks can pass without teaching the whole setupCompare the two modelsTriage failures and omissionsA checklist for your repositoryWhere DocsAlive fitsThe sources we checkedFAQThe short answer
pytest-markdown-docs collects eligible Python fences as pytest tests when you enable --markdown-docs. Its globals hook, fixtures and markers can make documentation examples convenient to run, but they also create test context that a reader may not have. Pin the plugin version, review what it collects, and make page prerequisites visible.
In engine 0.6.3, DocsAlive never reads conftest.py or plugin markers, runs blocks marked notest, shares one Python namespace per page, does not read docstrings, and does not treat .svx files as pages. Those differences can produce context findings or let a missing continuation pass. Keep pytest-markdown-docs for its collection and fixture semantics; use a page scan as a separate clean-sandbox check.
What the plugin collects
The PyPI page for pytest-markdown-docs 0.9.2 describes a pytest plugin for snippets in Markdown files and docstrings. Enable it with --markdown-docs; use -m markdown-docs to filter a mixed run to its tests. Fences starting with python, python3 or py are detected in .md, .mdx and .svx files and in class and function docstrings in .py files. notest in the info string excludes a fence.
Pin the installed version and follow the documentation for that release. The main-branch repository README documents options absent from 0.9.2: in the checked environment, --markdown-docs-only-text was rejected as an unrecognized argument. A command copied from a newer branch is not evidence that the installed release supports it.
A pytest_markdown_docs_globals hook in conftest.py returns a dictionary injected into every snippet. Autouse fixtures run, and named fixtures can be requested with fixture:NAME markers; their values are injected as globals. Autouse fixture values are injected only when named with a marker. Async fixtures are supported with pytest-asyncio.
continuation retains the side effects of the previous snippet. Without it, each block starts from the injected globals only. retry:N reruns a failing block up to N more times without rerunning fixtures. For Material for MkDocs, the pymdownx.superfences Markdown option can use the brace form for a continuation class when pytest runs with --markdown-docs-syntax=superfences. In .mdx, a pmd-metadata comment before a fence can carry notest, fixture, continuation and retry metadata. A pytest_markdown_docs_markdown_it hook can supply a custom markdown-it-py parser.
The project lists known issues: line numbers are wrong for docstring snippets and continuation blocks, assertions are not rewritten like ordinary pytest tests, and docstring discovery can traverse into the standard library. The project page’s capsys example captured an empty string in the checked run under 0.9.2 with pytest 9.2.0 and with pytest 8.4.2 on Python 3.13. The walkthrough uses tmp_path; that observation does not establish a confirmed bug.
Why blocks can pass without teaching the whole setup
An injected global can make a test pass while the page omits an import a reader needs. A fixture can provide a path or value that exists only in pytest. A missing continuation can break the plugin test even when a page-level runner preserves state automatically. A notest marker left on an example can exclude it long after the reason for excluding it has disappeared.
Review these as separate questions: does the plugin test the intended block, and can a reader reproduce the page with the prerequisites shown? The Python docs testing guide covers the broader workflow. For this walkthrough, acme-slug and acme_slug are illustrative names and are not published packages.
Set up globals and pages
This illustrative conftest.py makes slugify available to every Markdown snippet. It is pytest setup, not an import shown to the reader.
def pytest_markdown_docs_globals():
from acme_slug import slugify
return {"slugify": slugify}
The README imports its own dependency. That makes the block understandable independently of the hook.
# acme-slug
Make URL slugs from titles.
```python
from acme_slug import slugify
assert slugify("Release notes: v2.0") == "release-notes-v2-0"
```
The first version of the usage page relies on the injected global, carries state into a continuation, requests a fixture and excludes a planned feature. The planned feature is intentionally unavailable in the illustrative package.
# Usage
On these pages `slugify` is available without an import:
```python
assert slugify("Docs That Run") == "docs-that-run"
```
Build on the previous block with a continuation:
```python
from acme_slug import truncate_slug
slug = slugify("Testing docs examples with pytest")
```
```python continuation
assert truncate_slug(slug, 20) == "testing-docs"
```
Write a file with the tmp_path fixture:
```python fixture:tmp_path
page = tmp_path / "slug.txt"
page.write_text(slugify("Upgrade from 1.x"))
assert page.read_text() == "upgrade-from-1-x"
```
Planned for the next release:
```python notest
slugify("Ünïcode", ascii_only=True)
```
Install the plugin and enable its collection. The recorded run used pytest-markdown-docs 0.9.2.
python -m pip install pytest-markdown-docs
python -m pytest --markdown-docs -v
Five tests passed. The notest block was not collected at all, so its absence is part of the coverage story.
README.md::[CodeFence#1][line:5] PASSED [ 20%]
docs/usage.md::[CodeFence#1][line:5] PASSED [ 40%]
docs/usage.md::[CodeFence#2][line:11] PASSED [ 60%]
docs/usage.md::[CodeFence#3][line:17] PASSED [ 80%]
docs/usage.md::[CodeFence#4][line:23] PASSED [100%]
============================== 5 passed in 0.03s ===============================
Compare the page scan
This command plans a scan. With a top-level docs/ folder, the plain-project scope includes that folder and the root README: two pages with six Python blocks in this example.
docsalive scan .
In the recorded execution, the README block passed and all five usage blocks failed as depends-on-context. The engine did not read conftest.py, so it did not receive slugify or tmp_path; it also did not read notest. Depends-on-context is not a docs-bug category. Once the names resolve, an unavailable planned API can instead produce an api-drift finding.
The next illustrative edit imports what the page needs in its first visible block and removes the planned feature from the tested page.
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -1,8 +1,10 @@
# Usage
-On these pages `slugify` is available without an import:
+Import what the page uses in its first block:
```python
+from acme_slug import slugify
+
assert slugify("Docs That Run") == "docs-that-run"
```
@@ -25,9 +27,3 @@
page.write_text(slugify("Upgrade from 1.x"))
assert page.read_text() == "upgrade-from-1-x"
```
-
-Planned for the next release:
-
-```python notest
-slugify("Ünïcode", ascii_only=True)
-```
The plugin still passed five tests. In the new scan, the first three usage blocks passed; the fixture block remained depends-on-context because tmp_path exists inside pytest.
README.md::[CodeFence#1][line:5] PASSED [ 20%]
docs/usage.md::[CodeFence#1][line:5] PASSED [ 40%]
docs/usage.md::[CodeFence#2][line:13] PASSED [ 60%]
docs/usage.md::[CodeFence#3][line:19] PASSED [ 80%]
docs/usage.md::[CodeFence#4][line:25] PASSED [100%]
============================== 5 passed in 0.03s ===============================
If the continuation marker is removed, the plugin’s third usage block fails because it starts from injected globals rather than the previous snippet’s state. The page scan still passes that block because it shares one namespace per page.
NameError: name 'truncate_slug' is not defined
1 failed, 4 passed in 0.03s
The next package edit is broken on purpose: it renames truncate_slug while leaving the documentation unchanged.
--- a/acme_slug/__init__.py
+++ b/acme_slug/__init__.py
@@ -1,7 +1,7 @@
"""Make URL slugs from titles."""
import re
-__all__ = ["slugify", "truncate_slug"]
+__all__ = ["slugify", "shorten_slug"]
def slugify(title: str) -> str:
@@ -9,7 +9,7 @@
return re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-")
-def truncate_slug(slug: str, max_len: int) -> str:
+def shorten_slug(slug: str, max_len: int) -> str:
"""Shorten a slug to at most max_len characters without cutting a word."""
if len(slug) <= max_len:
return slug
pytest reported two failures and three passes. The scan classified the broken import as api-drift and the dependent continuation as depends-on-context. Investigate the first failure before treating both as independent defects.
ImportError: cannot import name 'truncate_slug' from 'acme_slug'
FAILED docs/usage.md::[CodeFence#2][line:13] - Error in code block:
FAILED docs/usage.md::[CodeFence#3][line:19] - Error in code block:
2 failed, 3 passed in 0.03s
In a mixed suite, use the plugin’s marker to select its tests. The unbroken version produced five passing tests with this command.
python -m pytest --markdown-docs -m markdown-docs
Compare the two models
| pytest-markdown-docs feature | What the plugin does | What the engine does in 0.6.3 |
|---|---|---|
| Globals hook | Injects the returned globals into snippets | Never reads conftest.py |
| Fixture marker | Injects the named fixture value | Does not read the marker or supply pytest fixtures |
notest |
Excludes the fence | Reads the first info-string word and runs the Python block |
continuation |
Keeps the previous snippet’s side effects | Ignores the marker and shares a namespace across the page |
retry:N |
Retries a failing block without rerunning fixtures | Does not read the marker |
Docstrings and .svx |
Detects eligible snippets | Does not read docstrings or treat .svx as a page |
| Output | Assertions in snippets can test values | Compares printed output only in pycon or python-repl sessions |
For pages scanned by both tools, a visible import in the first block gives both a shared starting point. Keep the globals hook if it helps your pytest suite, but avoid relying on it as the only explanation of a page’s prerequisites. Fixture-only blocks can be placed on pages outside the scan’s --include scope, or their depends-on-context findings can be reviewed as a known coverage gap.
Separate pages start with separate scan environments. A name defined on one page should not be assumed to exist on another. The plugin’s continuation model is narrower still: the marker matters to its test even when the scan’s page namespace masks its absence.
Triage failures and omissions
| Finding | Likely cause | What to do |
|---|---|---|
| Plugin reports an undefined name | Missing import, injected global or continuation | Check the preceding snippet and the installed hook |
| Scan reports depends-on-context | A fixture or injected name exists only in pytest | Make the prerequisite visible or record the fixture-only coverage gap |
| A planned feature runs in the scan | The engine ignores notest |
Keep it off tested pages |
| A block is absent from pytest | notest, file scope or fence recognition excluded it |
Review collection and the version’s rules |
| Scan passes but plugin fails | The page namespace masked a missing continuation | Restore or reconsider the marker and rerun pytest |
| An option is rejected | Documentation describes a different version | Pin the plugin and consult that version’s PyPI page |
| Later blocks fail after an import error | The earlier block did not establish state | Fix the first failure and rerun |
A clean checkout matters for scans: .pytest_cache/README.md can otherwise be picked up as a page. The engine also has a known limitation in which an unknown fence label can be reported as passing without execution or parsing. Inspect coverage and skip reasons, not just the final status.
For related collection models, see phmdoctest and Sybil. For site-specific context, see MkDocs docs testing.
A checklist for your repository
[ ] Pin pytest-markdown-docs and pytest versions.
[ ] Enable --markdown-docs and inspect the collected tests.
[ ] Review every notest marker and the reason for it.
[ ] Show page imports and prerequisites to readers.
[ ] Check each continuation and its preceding block.
[ ] Record fixture and globals-hook dependencies.
[ ] Check MDX metadata and the selected Markdown syntax option.
[ ] Run the page scan from a clean checkout.
[ ] Review depends-on-context findings and unsupported pages.
[ ] Rerun after API and documentation changes.
Where DocsAlive fits
pytest-markdown-docs is the authority for the plugin behaviors your suite uses. DocsAlive adds a page-oriented check in fresh containers and classifies findings for review. Its page scope and shared namespace answer a different question from pytest’s injected globals, fixture setup and continuation rules.
Use both results to make dependencies explicit. A plugin pass can confirm the configured test context; a page scan can reveal that the visible page does not establish a name. Neither result alone proves prose clarity or coverage of files the tool does not read. See the findings reference and CLI reference for interpreting and configuring scans.
The sources we checked
These sources were read on November 16, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| pytest-markdown-docs on PyPI | Version 0.9.2 collection, hooks, markers and known issues |
| pytest-markdown-docs repository | Main-branch project documentation and the version gap |
FAQ
How do I enable pytest-markdown-docs?
Install and pin the version you intend to use, then run pytest with --markdown-docs. The markdown-docs marker can select these tests in a mixed suite.
Why does a block need continuation?
Without the marker, the checked plugin version starts each block from injected globals only. Continuation keeps the previous snippet's side effects.
Can a snippet use a pytest fixture?
Yes. A fixture marker can request a named fixture and inject its value as a global. That value is pytest context, so explain any prerequisite a reader needs independently.
What does DocsAlive do with these pages in 0.6.3?
It never reads conftest.py or plugin markers, runs notest blocks, shares one namespace per page, does not read docstrings, and does not treat .svx as a page. Keep the plugin run for its collection and fixture semantics.
Why pin the plugin?
The main-branch README can describe options absent from the installed release. Pinning makes the behavior reproducible and lets the team consult the matching release documentation.
Does a passing test mean every example was collected?
No. A notest marker, file scope or fence format can exclude content. Review collection as well as test results.




