Last Updated: June 6, 2026
doctest is Python's built-in tool for turning the examples inside docstrings into actual tests. A function gets a few interactive REPL sessions pasted into its docstring to show how it works, and doctest runs them as tests on demand. It's the only framework where documentation and verification are literally the same characters.