xdoctest
A rewrite of the builtin doctest module
Decision gist · record as of 2026-08-14
Yes. Xdoctest is a mature, actively maintained tool with zero dependencies and broad Python support. It solves a real problem—keeping documentation examples in sync with code—and integrates cleanly into both standalone and pytest workflows. The permissive Apache 2 license poses no restriction. Install it if you want to treat docstring examples as executable tests.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.8 or later; Python 2.7 and 3.4–3.7 are no longer supported as of version 1.1.0 and 1.2.0 respectively.
- Installation is straightforward with no runtime dependencies.
- The package is actively maintained, with a recent release and ongoing commits.
License · maintenance · safety
Apache 2 (permissive) — Apache 2 is a permissive license, allowing use in most commercial and open-source projects without significant restriction.
last release 2026-03-27 (140 days) · last repo commit 2026-07-14 · 223 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,091,491 downloads/mo, #4,379 on PyPI
Alternatives
Verify before relying
pip install xdoctest
# Run all doctests in a module
python -m xdoctest /path/to/module.py all
# Or with pytest
pytest --xdoctest /path/to/module.py- Performance characteristics when running doctests on large codebases or deeply nested modules
- Specific AST parsing edge cases or limitations compared to the built-in doctest module
- Compatibility with all pytest plugins or configurations
What it is and what it does
Xdoctest is a replacement for Python's built-in doctest module that discovers and executes example code written in docstrings. Instead of using regex-based parsing, it employs an abstract-syntax-tree parser for more reliable detection and execution of doctests. The package encourages writing tests and documentation together in the same file, reducing boilerplate and helping developers maintain minimal working examples alongside their code.
You can run xdoctest either as a standalone command-line tool or as a pytest plugin. The standalone interface lets you execute all doctests in a module, list them, dump them as unit tests, or run specific functions' doctests. The pytest integration allows you to run doctests alongside your regular unit tests using a single command, making it practical for CI pipelines. The package is actively maintained, supports Python 3.8 through 3.14, and has no external runtime dependencies.
Use it for
- Validate example code in function and class docstrings during development or CI to catch documentation drift
- Write minimal working examples in docstrings that serve as both documentation and regression tests
- Run all doctests in a project with a single command to ensure examples remain executable
- Integrate doctest execution into pytest workflows alongside unit tests for comprehensive test coverage
- Debug functions by first writing example inputs and outputs in docstrings, then implementing the body
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Xdoctest is a mature, actively maintained tool with zero dependencies and broad Python support. It solves a real problem—keeping documentation examples in sync with code—and integrates cleanly into both standalone and pytest workflows. The permissive Apache 2 license poses no restriction. Install it if you want to treat docstring examples as executable tests.
Install
xdoctest on PyPI
Before you install
Installation is straightforward with no runtime dependencies. The package is actively maintained, with a recent release and ongoing commits. It supports modern Python versions (3.8+) across CPython and PyPy implementations.
Requires Python 3.8 or later; Python 2.7 and 3.4–3.7 are no longer supported as of version 1.1.0 and 1.2.0 respectively.
License in practice
Apache 2 is a permissive license, allowing use in most commercial and open-source projects without significant restriction.
Quickstart
pip install xdoctest
# Run all doctests in a module
python -m xdoctest /path/to/module.py all
# Or with pytest
pytest --xdoctest /path/to/module.py
Verify before relying
- Performance characteristics when running doctests on large codebases or deeply nested modules
- Specific AST parsing edge cases or limitations compared to the built-in doctest module
- Compatibility with all pytest plugins or configurations
Package facts
| License | Apache 2 permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 140 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,091,491 / month, #4,379 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 6 - MatureFramework :: PytestIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: TestingTopic :: Utilities |
Evidence: xdoctest-1.3.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “execute doctests”
- xdoctestXdoctest finds and executes test code embedded in Python docstrings,…
- pytest-cythonA pytest plugin that runs doctests embedded in Cython `.pyx`…
- pytest-doctestplusA pytest plugin that runs doctests in Python docstrings and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also pytest-doctestplus · pytest-cython · lib-detect-testenv · sybil · pytest-extra-durations · zope.testing · pytest-durations · pytest-markdown-docs · nose · interrogate