Python Doctest Considered Awesome

Christer Enfors
The Startup
Published in
4 min readMar 12, 2020

--

Doctest is a really clever built-in Python module that allows you to embed automated tests in documentation strings. If you’re somewhat new to Python and that sounds complicated — it isn’t. It is very easy to set up; I will show you how.

A screenshot of a simple Python function, with a working doctest. This function is included as text further down.
A screenshot of a simple Python function, with a working doctest.

How documentation strings work in Python

--

--

Christer Enfors
The Startup

Parent, gamer, professional software development nerd and amateur martial arts nerd. Loves roleplaying games. https://ttrpg-hangout.social