pytest-codeblocks
Test code blocks in your READMEs
Decision gist · record as of 2026-08-14
Yes. Low install friction, no security vulnerabilities, permissive MIT license, and active maintenance make this a straightforward addition to any project with documentation that includes runnable code. It solves a real problem—keeping examples in sync with code—with minimal overhead.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction install with a single runtime dependency on pytest.
- Actively maintained with a release within the last 60 days and marked as Production/Stable.
License · maintenance · safety
permissive license (permissive) — MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
last release 2026-06-15 (60 days)
0 known vulnerabilities (OSV.dev, 2026-08-14) · 186,361 downloads/mo, #9,989 on PyPI
Alternatives
Verify before relying
pip install pytest-codeblocks
# In your README.md, add code blocks with python or sh syntax highlighting
# Then run:
pytest --codeblocks- Whether the plugin handles edge cases like nested code blocks or complex markdown structures.
- Performance characteristics when testing large numbers of code blocks across many files.
What it is and what it does
pytest-codeblocks is a pytest plugin that treats code blocks in markdown files—particularly READMEs—as executable test cases. It discovers blocks marked with python, sh, bash, or zsh syntax highlighting and runs them through pytest, letting you verify that documentation examples actually work.
The plugin supports marking code blocks with pytest directives (skip, skipif, xfail) via HTML comments, merging fragmented examples across multiple blocks, and validating expected output. This catches a common documentation debt: examples that drift out of sync with the actual codebase. It depends only on pytest and requires Python 3.10 or later.
Use it for
- Verify that code examples in a project's README actually execute without errors.
- Catch breaking changes when refactoring by running documented usage patterns as tests.
- Validate shell command sequences and their output in installation or setup documentation.
- Ensure multi-step code examples work when split across separate markdown blocks.
- Skip or mark code blocks as expected-to-fail for examples that demonstrate error handling.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Low install friction, no security vulnerabilities, permissive MIT license, and active maintenance make this a straightforward addition to any project with documentation that includes runnable code. It solves a real problem—keeping examples in sync with code—with minimal overhead.
Install
pytest-codeblocks on PyPI
Before you install
Low friction install with a single runtime dependency on pytest. Actively maintained with a release within the last 60 days and marked as Production/Stable.
Requires Python 3.10 or later.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install pytest-codeblocks
# In your README.md, add code blocks with python or sh syntax highlighting
# Then run:
pytest --codeblocks
Verify before relying
- Whether the plugin handles edge cases like nested code blocks or complex markdown structures.
- Performance characteristics when testing large numbers of code blocks across many files.
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagepytest |
| Maintenance | Actively maintained 60 days since the last release |
| First released | |
| Downloads | 186,361 / month, #9,989 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 |
Evidence: pytest_codeblocks-0.18.0-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 › “test code blocks in markdown”
- pytest-codeblocksA pytest plugin that automatically discovers and runs Python and…
- pytest-markdown-docsA pytest plugin that executes Python code snippets embedded in…
- doccmdRuns linters, formatters, and other command-line tools against code…
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 pytest-markdown-docs · pytest_tagging · pytest-md · pytest-doctestplus · pytest-examples · pytest-skip-slow · pytest-describe · pytest-dependency · markdown-callouts · pytest-skip-markers