Skip to main content
Tests Latest Version https://img.shields.io/pypi/wheel/pytest-rst.svg https://img.shields.io/pypi/pyversions/pytest-rst.svg https://img.shields.io/pypi/l/pytest-rst.svg

A pytest plugin that discovers and runs Python code blocks embedded in reStructuredText files as test cases.

Installation

pip install pytest-rst

Usage

Add a :name: option starting with test_ to any Python code block in your .rst files, and pytest will collect and run it automatically:

.. code-block:: python
    :name: test_example

    assert 2 + 2 == 4
assert 2 + 2 == 4

Code blocks without a test_ name are ignored:

.. code-block:: python

    # this will not be collected by pytest
    assert False
# this will not be collected by pytest
assert False

Fixtures

Code blocks can request pytest fixtures. Fixtures are injected into the code block’s namespace. There are two syntaxes: a directive option and a comment.

Directive option (:fixtures:)

Use the :fixtures: directive option on the code block:

.. code-block:: python
    :name: test_file_ops
    :fixtures: tmp_path

    p = tmp_path / "test.txt"
    p.write_text("hello")
    assert p.read_text() == "hello"

Comment syntax (# fixtures:)

Use a # fixtures: comment inside the code block. This is recommended when your RST files are uploaded to PyPI, because PyPI’s renderer rejects unknown directive options like :fixtures:.

# fixtures: tmp_path
p = tmp_path / "test.txt"
p.write_text("hello")
assert p.read_text() == "hello"

Multiple fixtures (comma-separated):

# fixtures: tmp_path, capsys
print("hello")
p = tmp_path / "f.txt"
p.write_text("ok")
assert p.read_text() == "ok"
captured = capsys.readouterr()
assert captured.out == "hello\n"

The # fixtures: line is stripped before execution and does not affect your code. Both syntaxes can be combined — fixture names are merged.

Any pytest fixture works, including custom ones defined in conftest.py.

Versioning

This software follows Semantic Versioning.

Release files for pytest-rst 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-rst 0.2.3
File Size Uploaded
pytest_rst-0.2.3.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-rst 0.2.3
File Interpreter ABI Platform
pytest_rst-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / pytest_rst-0.2.3.tar.gz

Download URL pytest_rst-0.2.3.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a450372bb203d2d1eda92c809cafdd171f0920ff576dcded4f85b294ca08b068
BLAKE2b-256 checksum
How to use checksums
16889c4ff99a0b7b12d8da1c77e77e69e6faf7d3529bd2cba931b94f5adcd492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 22, 2026.

Transparency log

Release files / pytest_rst-0.2.3-py3-none-any.whl

Download URL pytest_rst-0.2.3-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d69592f335dfb706e7cc526c824f3e68497e9571f9733fbd2738b536aafe83e3
BLAKE2b-256 checksum
How to use checksums
aab00c1060cf6ad03f12f8eee671183463c1152d0aa2442fb812ec7cb73680a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.7

1 release file

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page