Skip to main content

Run pytest --doctest-modules with markdown docstrings (code blocks)

Project description

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).

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

  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-modules

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

[tool.pytest.ini_options]
addopts = [
    "--doctest-modules",
]

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

pytest-doctest-mkdocstrings-0.0.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

pytest_doctest_mkdocstrings-0.0.4-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest-doctest-mkdocstrings-0.0.4.tar.gz.

File metadata

File hashes

Hashes for pytest-doctest-mkdocstrings-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e19cf1bfbcc636edac18d6958f65fe8d60ee981ea42097acbbad56883a6e0eec
MD5 276c7a4acb95c1dd2f22667798105a01
BLAKE2b-256 2ad3c135997dd0c8a9419b6022811b60fa7aba24afaadc8c9202212a3245dd18

See more details on using hashes here.

File details

Details for the file pytest_doctest_mkdocstrings-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_doctest_mkdocstrings-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 67d9af2636ed8e045520dd24e198e72ab9f7fdb68bdd40e5b5007b234a4a8282
MD5 fe466cc5cf60c48394092c7a88dd6de5
BLAKE2b-256 699835ca36a995b373405df5cf87e176f9f834a4412bc2850999857c3aaef91c

See more details on using hashes here.

Supported by

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