pytest-doctestplus

1.7.1 · active · verified Sun Apr 12

pytest-doctestplus is a pytest plugin that extends the standard Python doctest functionality with advanced features for testing example code in Python docstrings, reStructuredText (.rst), Markdown (.md), and TeX (.tex) files. It is currently at version 1.7.1 and maintains a consistent release cadence with new features, bug fixes, and compatibility updates for Python and pytest versions.

Warnings

Install

Quickstart

To quickly test doctests using pytest-doctestplus, place your doctests in docstrings or .rst files. Then, simply invoke pytest with the `--doctest-plus` flag. This example shows a simple function with a doctest and how to run it, including a skipped test using a doctest directive.

import pytest

# my_module.py
def greet(name):
    """
    Greets the given name.

    >>> greet('World')
    'Hello, World!'

    >>> greet('pytest-doctestplus') # doctest: +SKIP
    'Hello, pytest-doctestplus!'
    """
    return f'Hello, {name}!'

# To run the doctests from the command line, save the above as my_module.py
# and run pytest:
# pytest --doctest-plus my_module.py

view raw JSON →