pytest-ruff-markdown
A pytest plugin that lints python / py fenced code blocks in Markdown files with ruff. Each fenced block in a collected .md file becomes its own pytest item.
Installation
Add it as a dev dependency in your project:
uv add --dev pytest-ruff-markdown
No further configuration is needed: once installed, pytest automatically
collects every ```python/```py fenced block in any .md file it
picks up (other fence languages, e.g. ```bash, are left alone) and lints
it as its own test item. A violation is reported against the block's real
line number in the Markdown file, not the block's own internal line
numbers, so failures jump you straight to the offending line in your docs.
Usage notes
Each fenced block is linted as its own isolated file — it has no visibility
into any other block in the same document, or into surrounding prose. That
means F821/F401 can fire on names or imports that are actually defined
in a different block (for example, a class split across two fences). This
is intentional: isolated linting is what gives each block its own
pass/fail and its own line number, and it's the plugin's main value. A
block can opt out of linting entirely with a skip marker, or opt into
sharing a preceding block's source as context with a continues marker:
<!-- pytest-ruff-markdown: skip -->
<!-- pytest-ruff-markdown: continues -->
Formatting (ruff format) is a mutation, not a check, so it runs via a
separate console script instead of as a pytest item:
uv run pytest-ruff-markdown-format docs/tutorial.md
Each block is piped into ruff under a synthetic filename of the form
{markdown-stem}__blockN.py, resolved next to the source Markdown file
(e.g. docs/tutorial.md's second block becomes docs/tutorial__block2.py).
This is a stable contract you can target with your own ruff
per-file-ignores config to scope rules for embedded code specifically,
without any plugin-specific configuration.
See the reference docs for full details on the
markers, the synthetic filename contract for scoping your own ruff
config, the D100 suppression, and the pytest-ruff-markdown-format CLI
flags.
Release files for pytest-ruff-markdown 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_ruff_markdown-0.1.0.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_ruff_markdown-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / pytest_ruff_markdown-0.1.0.tar.gz
| Download URL | pytest_ruff_markdown-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f11715e663498ce8354983f8268394ce7eb8e14dcec9f8be8ef1670ed1a0a2b4
|
|
BLAKE2b-256 checksum How to use checksums |
6a6613a62969f865e013301861fa7685ae129e7c84a36228ca7cbea2361f3fdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytest_ruff_markdown-0.1.0-py3-none-any.whl
| Download URL | pytest_ruff_markdown-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ccceac3d44777ee84239904c23056c4ff76260c31f3d39d4bb129e105a0c6e9e
|
|
BLAKE2b-256 checksum How to use checksums |
a93ad2d6dd217dca27ed2f34c339f4ac844ed3bcd7348804bbb551915db8af0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|