Registry / testing / xdoctest

xdoctest

JSON →
library1.3.2pypypi✓ verified 23d ago

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.

pip install xdoctest
INSTALL
IMPORT
SIG · XDOCTEST
X
xdoctest
testingpythonv1.3.2
Install
6.7s avg
Import
298ms
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.312s · 18.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 6.7s · import 0.283s · 19MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

doctest_module
from xdoctest import doctest_module
import xdoctest

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')
xdoctest --version
Debug
Known issues
breakingxdoctest dropped support for Python 3.6 and 3.7.
fix
Ensure your project uses Python 3.8 or newer. For projects requiring Python 3.6 or 3.7, pin xdoctest to version `<=1.1.6`.
affects: >=1.2.0
breakingThe deprecated CLI flags `--xdoc-force-dynamic` and `--allow-xdoc-dynamic` were removed.
fix
Update your CLI commands to remove these flags. xdoctest's dynamic behavior is now handled by default or through other mechanisms. Refer to the official documentation for current CLI options.
affects: >=1.3.0
gotchaWhen using `xdoctest` with `pytest`, its integration mechanism changed.
fix
xdoctest now uses the standard pytest plugin system to disable the stdlib `doctest` module instead of monkey patching. This generally means better compatibility and fewer conflicts, but might affect highly customized test setups. Standard usage (e.g., `pytest --xdoctest`) should continue to work as expected.
affects: >=1.3.0
gotchaDiscovering doctests in `async def` functions and using top-level `await` or the `ASYNC` directive.
fix
Ensure you are on xdoctest version 1.3.2 or later for full and robust support for `async def` function discovery and correct line number reporting. Version 1.3.0 introduced the `ASYNC` directive for managing the asyncio event loop within tests, and 1.2.0 added support for top-level awaits.
affects: <1.3.2 (especially <1.3.0 for `ASYNC` directive)
gotchaIssues with module path resolution, especially for packages installed in editable mode.
fix
Multiple fixes for `modname_to_modpath` were applied in versions 1.1.3, 1.1.4, and 1.1.5. If you encounter errors related to module discovery, particularly with editable installs or when module names differ from package names, ensure you are using xdoctest version 1.1.5 or newer.
affects: <1.1.5 (especially during 1.1.3 and 1.1.4)
Upgrade
Version history
1.3.2latest on PyPI · released Mar 27, 2026
Audit
Dependencies
pytestoptionalRequired for pytest integration, though xdoctest can be used standalone.
Agent activity
15 hits · last 30 days
node
14
Resources
xdoctest — pip install xdoctest · libregistry