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
TL;DR: invoke pytest with
--doctest-mdcodeblocks
- Strongly recommended to set up a virtual environment first! (e.g..
python3 -m venv .venv
,. .venv/bin/activate
) - Install with
pip install pytest-doctest-mkdocstrings
- 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
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
Hashes for pytest-doctest-mkdocstrings-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 272c07e4ec80dd8d745ddce6d97d3610ef56eb88bcb20f64f9eb33304f7c152f |
|
MD5 | a128255e23a9f597320a059a8fd29323 |
|
BLAKE2b-256 | 8c3267e21106b6e482c238ba64230de20b9f0f286b3a56902fd40285f9c1b00a |
Hashes for pytest_doctest_mkdocstrings-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e8a3ea9fac2ceea34fc80c39f579f6b9f91f6b86600c77829462e929cef7df |
|
MD5 | 4d0d0fd9f52f9f8b736b10f1c5002355 |
|
BLAKE2b-256 | cf20e2af6a8be235dba2086ef90bd8eeda7e158f1b323a80840a05b87440ba39 |