xdoctest

1.3.2 · active · verified Sun Apr 12

xdoctest is a powerful and flexible rewrite of Python's builtin `doctest` module, designed for better integration with modern development workflows, especially pytest. It offers enhanced features like static analysis, improved error reporting, and dynamic code execution. The current version is 1.3.2, and it maintains an active release cadence with frequent updates addressing features and bug fixes.

Warnings

Install

Imports

Quickstart

Create a Python file with doctests, then run them directly using the xdoctest CLI or programmatically. If pytest is installed, simply running `pytest --xdoctest` will discover and run xdoctests.

# my_module.py
def add_one(x):
    """
    >>> add_one(1)
    2
    >>> add_one(0)
    1
    """
    return x + 1

# Run tests from the command line
# In your terminal:
# python -m xdoctest my_module.py

# Or programmatically:
import xdoctest
# For doctesting a specific module (e.g., 'my_module')
xdoctest.doctest_module('my_module')

view raw JSON →