Skip to main content

pytest-doctest-mkdocstrings

A pytest plugin that allows you to use doctest and enclose your example code blocks in ``` codeblocks (e.g. when building documentation with mkdocs and mkdocstring).

v0.1.0 - Breaking change - you now need to specifically add the command line option --doctest-mdcodeblocks when calling pytest

Usually this docstring would fail doctest:

    """
    A function description

    Examples:
    --------
    ```
    >>> x = 1
    >>> x
    1
    ```
    """

As doctest looks for the output

Expected:
    1
    ```
Got:
    1

This plugin works by mockeypatching doctests parser when pytest begins each test session and including ``` as an identifier of the end of an expected result (a want).

It only works when doctest is invoked via pytest, not when invoking doctest directly.

If you have code examples or expected results which actually contain ``` then you'll need to re-write them.

Usage

TL;DR: invoke pytest with --doctest-mdcodeblocks

  1. Strongly recommended to set up a virtual environment first! (e.g.. python3 -m venv .venv, . .venv/bin/activate)
  2. Install with pip install pytest-doctest-mkdocstrings
  3. Run pytest: pytest --doctest-mdcodeblocks --doctest-modules --doctest-glob="*.md"

You can also add the following to your pyproject.toml so that pytest always runs doctests:

[tool.pytest.ini_options]
addopts = [
    "--doctest-modules",
    "--doctest-glob='*.md'",
    "--doctest-mdcodeblocks"
]

To temporarily override the setting use: pytest --no-doctest-mdcodeblocks

Release files for pytest-doctest-mkdocstrings 0.1.1

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-doctest-mkdocstrings 0.1.1
File Size Uploaded
pytest-doctest-mkdocstrings-0.1.1.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-doctest-mkdocstrings 0.1.1
File Interpreter ABI Platform
pytest_doctest_mkdocstrings-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / pytest-doctest-mkdocstrings-0.1.1.tar.gz

Download URL pytest-doctest-mkdocstrings-0.1.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a3b361e016917a79e268dc4e120a50e216e7f67527d0a53cb454392a077f003a
BLAKE2b-256 checksum
How to use checksums
86863f430d371c07ac7f1a391a853d9d675a4422af2337f59ac2431331749252
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / pytest_doctest_mkdocstrings-0.1.1-py3-none-any.whl

Download URL pytest_doctest_mkdocstrings-0.1.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2299264438723ad1b287a0ad6c2e0b30a99e80711381eb6e97284810237b71b2
BLAKE2b-256 checksum
How to use checksums
028e7cbab493901a48c0dc8e45e55f126c3bb100693c65c234ebcb9085d55075
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.4

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