doctest

doctest is a module included in the Python programming language's standard library that allows the easy generation of tests based on output from the standard Python interpreter shell, cut and pasted into docstrings.

Docstrings can in turn be extracted from program files to generate documentation in other formats such as HTML or PDF.

On the basis of the output of Python's interactive interpreter, text can be mixed with tests that exercise the library, showing expected results.

In C++, the doctest framework is the closest possible implementation of the concept – tests can be written directly in the production code with minimal overhead and the option to strip them from the binary.

[8] byexample[9] supports writing doctests for several popular programming languages (e.g. Python, Ruby, Shell, JavaScript, C/C++, Java, Go, Rust) inside Markdown, reStructuredText and other text documents.