pytest-markdown-docs
Run markdown code fences through pytest
Decision gist · record as of 2026-08-14
Yes. The plugin solves a real problem—keeping documentation examples in sync with code—with low friction and active maintenance. MIT licensing removes legal concerns. It integrates cleanly into existing pytest workflows via a command-line flag. Suitable for projects that prioritize documentation quality and want automated validation of code examples.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.9 or later; pytest must be installed as a runtime dependency.
- Low install friction with only two runtime dependencies (pytest and markdown-it-py).
- Active maintenance with a recent release on 2026-03-23 and last commit on 2026-06-11.
License · maintenance · safety
MIT (permissive) — MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
last release 2026-03-23 (144 days) · last repo commit 2026-06-11 · 85 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 300,279 downloads/mo, #7,843 on PyPI
Alternatives
Verify before relying
pip install pytest-markdown-docs
# In a markdown file or docstring:
# ```python
# import mymodule
# result = mymodule.Foo().bar()
# assert result == "hello"
# ```
pytest --markdown-docs- Whether line number reporting in tracebacks is sufficiently accurate for debugging docstring-inlined tests.
- Performance impact when running against large markdown files or many code snippets.
- Compatibility with pytest plugins that also modify test discovery or execution.
What it is and what it does
pytest-markdown-docs is a pytest plugin that treats Python code blocks in markdown files and docstrings as executable test cases. It scans for fenced code blocks (triple backticks) marked with python, python3, or py language tags, and runs them through pytest's test framework. This bridges the gap between documentation and testing: code examples in your README, API docs, or docstrings can be automatically validated to ensure they remain correct as your codebase evolves.
The plugin supports several advanced features: skipping blocks with notest markers, injecting global variables or fixtures into code blocks, using pytest fixtures (including async fixtures from pytest-asyncio), chaining snippets with continuation markers to maintain state across blocks, and retrying flaky tests. It also handles MDX files with metadata comments and supports custom markdown-it-py parser configurations for compatibility with tools like Material for MkDocs.
Use it for
- Validate code examples in README files and API documentation to prevent outdated or broken examples.
- Test docstring examples in library code without duplicating assertions in separate test files.
- Ensure tutorial markdown files contain working, up-to-date code snippets that readers can trust.
- Catch regressions in documented usage patterns when refactoring library APIs.
- Generate living documentation where code examples are guaranteed to execute correctly.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The plugin solves a real problem—keeping documentation examples in sync with code—with low friction and active maintenance. MIT licensing removes legal concerns. It integrates cleanly into existing pytest workflows via a command-line flag. Suitable for projects that prioritize documentation quality and want automated validation of code examples.
Install
pytest-markdown-docs on PyPI
Before you install
Low install friction with only two runtime dependencies (pytest and markdown-it-py). Active maintenance with a recent release on 2026-03-23 and last commit on 2026-06-11.
Requires Python 3.9 or later; pytest must be installed as a runtime dependency.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install pytest-markdown-docs
# In a markdown file or docstring:
# ```python
# import mymodule
# result = mymodule.Foo().bar()
# assert result == "hello"
# ```
pytest --markdown-docs
Verify before relying
- Whether line number reporting in tracebacks is sufficiently accurate for debugging docstring-inlined tests.
- Performance impact when running against large markdown files or many code snippets.
- Compatibility with pytest plugins that also modify test discovery or execution.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesmarkdown-it-pypytest |
| Maintenance | Actively maintained 144 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 300,279 / month, #7,843 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: pytest_markdown_docs-0.9.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “markdown documentation testing”
- pytest-markdown-docsA pytest plugin that executes Python code snippets embedded in…
- pytest-codeblocksA pytest plugin that automatically discovers and runs Python and…
- sybil-extrasProvides specialized evaluators and parsers that extend Sybil, a…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also markdown-exec · pytest-codeblocks · pytest-describe · lib-detect-testenv · doccmd · sybil · pytest-md · pytest-examples · pytest-doctestplus · sybil-extras