Search notes:

Python standard library: doctest

doctest finds code-examples in a module's docstrings and executes those, tyipcally for testing purposes.

Simple demonstration

The following simple module is supposed to demonstrate how doctest could be used.
def func(a, b, c):

    """ The purpose of this function is to demonstrate
        how sipmle testcases can be embedded itno
        a function's docstring

    >>> func(9, 21, 12)
    42
    """

    return a+b+c

def willFail(a, b, c):

    """ Testing this function will fail because '42'
        is intented to far. The output will be something
        like
          Expected:
                  42
          Got:
              42

    >>> func(9, 21, 12)
        42
    """

    return a+b+c

import doctest
doctest.testmod()
Github repository about-Python, path: /standard-library/doctest/theModule.py

See also

The unittest module is a bit more elaborate and modelled after Java and SmallTalk testing frameworks.
standard library

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1738304425, '18.218.94.236', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/standard-library/doctest(78): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78