--- id: pytest-markdown-docs version: "0.9.2" license: MIT license_treatment: permissive maintenance: active --- # pytest-markdown-docs — Run markdown code fences through pytest License: permissive · Maintenance: active · Downloads: 300.3K/mo ## 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 above — verify before relying. A pytest plugin that executes Python code snippets embedded in markdown files and docstrings as automated tests, detecting fenced code blocks and inline examples. 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 pip install pytest-markdown-docs uv add pytest-markdown-docs poetry add pytest-markdown-docs ## Installing pytest-markdown-docs 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. 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 Requires Python 3.9 or later; pytest must be installed as a runtime dependency. 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_current - Install friction: low - Maintenance: active - Downloads: 300.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags markdown code snippet testing, pytest markdown plugin, docstring code examples as tests, markdown documentation testing, executable code fence validation, pytest doctest alternative, markdown code block runner, documentation-testing, pytest-plugin, example-validation [View on SkillFed](https://skillfed.io/packages/pytest-markdown-docs) · [View on PyPI](https://pypi.org/project/pytest-markdown-docs/)