A pytest extension to test console code blocks in markdown files.
Project description
A pytest extension to test console code blocks in Markdown files
A minimal pytest extension to test console blocks in your Markdown documentation. Works on Linux, macOS, and Windows.
Installation
In your project, run:
pip install pytest-markdown-console
If you are using uv, install it as a development dependency:
uv add --dev pytest-markdown-console
The plugin self-registers and will run in each subsequent pytest invocation.
How does it work?
Each console code block in Markdown files collected by the plugin generates a test case.
The test runs each command in the block and compares its actual output to the expected output written in the block.
For example:
```console
$ uv run myapp.py
Hello, world!
```
This creates a passing test case if your app actually prints "Hello, world!".
Signal expected failures
Sometimes you want to illustrate expected failures. To convey this to both the reader and the plugin, place a # Error: comment at the end of the failing command, or on the line preceding it:
```console
$ uv run myapp.py --bad_option # Error: this will fail
$ # Error: this will also most definitely fail
$ uv run myapp.py --still_bad
```
Filter by platform
To restrict a test to specific platforms, use the platform: directive:
```console platform:linux,macos
$ echo "This will generate a test case on Linux and macOS"
```
To exclude a platform, prefix its name with !:
```console platform:!windows
$ echo "This will not generate a test case on Windows"
```
Change the working directory
By default, all commands run in the same directory as the Markdown file. To use a different directory, use the cwd: directive:
```console cwd:../
$ uv run myapp.py
...
```
Relative paths are resolved relative to the Markdown file's location.
Controlling which tests run
By default, all tests run including those generated by this plugin. To exclude them:
pytest -p no:markdown-console
To run only the plugin's tests:
pytest -m markdown_console
Why this extension?
This plugin makes your documentation testable — specifically console blocks — within the same pytest suite you use for the rest of your code.
It is similar to pytest-markdown-docs, which works on Python code blocks, and follows similar conventions.
Other tools can test console blocks in Markdown files, but we couldn't find one that is simple, supports Windows, integrates with pytest, and requires no boilerplate.
Does it make sense to test console blocks?
Testing console blocks is admittedly niche. They often contain installation instructions or shell-specific commands that don't translate across platforms.
However, if you are building a CLI app, you likely already showcase commands and their output in your docs. Testing those snippets ensures they stay up-to-date.
Launching a Python app on Windows, Linux, or macOS is the same one-liner when using uv. That is the sweet spot motivating this small plugin.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_markdown_console-0.0.1.dev1.tar.gz.
File metadata
- Download URL: pytest_markdown_console-0.0.1.dev1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a665d91e05a5f142739b8faf8434bb75442d937e1f8764df2bd6bed09e1bbdb3
|
|
| MD5 |
a71f41a6510ff5dddb8e077c426e61ba
|
|
| BLAKE2b-256 |
83832fc192fea2f2b7fe83d6d427beccf7c43cbbef69cbe129cc99314545368d
|
Provenance
The following attestation bundles were made for pytest_markdown_console-0.0.1.dev1.tar.gz:
Publisher:
publish.yml on confarg/pytest-markdown-console
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_markdown_console-0.0.1.dev1.tar.gz -
Subject digest:
a665d91e05a5f142739b8faf8434bb75442d937e1f8764df2bd6bed09e1bbdb3 - Sigstore transparency entry: 1647053054
- Sigstore integration time:
-
Permalink:
confarg/pytest-markdown-console@b20b0ef1e7b01a5e7a1262d762bf0c3f1d4b1116 -
Branch / Tag:
refs/tags/v0.0.1.dev1 - Owner: https://github.com/confarg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b20b0ef1e7b01a5e7a1262d762bf0c3f1d4b1116 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_markdown_console-0.0.1.dev1-py3-none-any.whl.
File metadata
- Download URL: pytest_markdown_console-0.0.1.dev1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dec1decaabcee3092b13c33a942ac54b503ccde8b556c1708c227290b7c83be4
|
|
| MD5 |
76243ed2b522919e483e0df5175c4132
|
|
| BLAKE2b-256 |
700a512d09bb7eaa321fae8b0dfd04ce14ccf59019b446e1b91f726f8a1c5057
|
Provenance
The following attestation bundles were made for pytest_markdown_console-0.0.1.dev1-py3-none-any.whl:
Publisher:
publish.yml on confarg/pytest-markdown-console
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_markdown_console-0.0.1.dev1-py3-none-any.whl -
Subject digest:
dec1decaabcee3092b13c33a942ac54b503ccde8b556c1708c227290b7c83be4 - Sigstore transparency entry: 1647053272
- Sigstore integration time:
-
Permalink:
confarg/pytest-markdown-console@b20b0ef1e7b01a5e7a1262d762bf0c3f1d4b1116 -
Branch / Tag:
refs/tags/v0.0.1.dev1 - Owner: https://github.com/confarg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b20b0ef1e7b01a5e7a1262d762bf0c3f1d4b1116 -
Trigger Event:
release
-
Statement type: