Skip to main content

Pytest plugin that executes README code examples.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - Version


Overview

swarmauri_tests_readme_examples is a pytest plugin that turns Markdown code blocks into executable tests. It scans README (or other documentation) files for Python examples and verifies that every runnable block still executes successfully. This keeps documentation trustworthy without hand-maintained test_readme_example.py scaffolding.

The plugin works out of the box for Python code blocks (```python, ```py, ```pycon) and exposes command-line flags and pyproject.toml settings so you can fine-tune which files and languages are exercised.

Installation

pip install swarmauri_tests_readme_examples

pytest discovers the plugin automatically after installation.

Quick Start

Run pytest as usual to execute every Python code block in README.md:

pytest

Sample failure output:

E   README.md::block-3 raised ValueError('boom')

Configuration

You can control the scan through CLI options or pyproject.toml:

  • --readme-files – comma/newline separated Markdown files (default: README.md)
  • --readme-languages – languages to execute (default: python, py, pycon)
  • --readme-modeparameterized (default) or aggregate
  • --readme-skip-markers – comment markers that skip a block when they appear on the first non-empty line

pyproject.toml example (under [tool.pytest.ini_options]):

[tool.pytest.ini_options]
readme_files = """
    README.md
    docs/guide.md
"""
readme_languages = """
    python
    py
"""
readme_mode = "aggregate"
readme_skip_markers = """
    # pytest: skip-example
    # docs: skip
"""

Skipping Blocks

Place one of the configured skip markers on the first non-empty line to leave a code block out of execution:

```python
# pytest: skip-example
print("shown in docs, ignored in tests")
```

Aggregate Mode

Switch to --readme-mode=aggregate (or set readme_mode = "aggregate") to collapse all README checks into a single pytest item that aggregates every failure message. This is handy when you want a brief summary rather than many individual tests.

License

Licensed under the Apache 2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_tests_readme_examples-0.1.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_tests_readme_examples-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_tests_readme_examples-0.1.1.tar.gz.

File metadata

  • Download URL: swarmauri_tests_readme_examples-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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}

File hashes

Hashes for swarmauri_tests_readme_examples-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7a5d789f7e174febfc2b91afd1c3bc63e20afe3ca8858ad62d769412b122fc86
MD5 dd0fb10fe1969f1eb0df1056d4f4a6a9
BLAKE2b-256 ae22b838b968c7e4684374d8a12cd7d35a80f0f9c3db1fa53525da55c964b0d7

See more details on using hashes here.

File details

Details for the file swarmauri_tests_readme_examples-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_tests_readme_examples-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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}

File hashes

Hashes for swarmauri_tests_readme_examples-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3043ab610a3d616707a7620ee15490cd57f2ffcb0ceefb1907e869c2e7dce9d
MD5 4e6af9aff012dbb872753aeeb3d88e0d
BLAKE2b-256 5cb0d8d84546401eec31da9a03e2f217ea5bdb2854a9016fb031765807212e64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page