For quick and simple testing, you might like to have a look at doctests.
To write the tests, you place things that look like interactive interpreter sessions in a docstring:
def my_function(n):
"""Return n + 5
>>> my_function(500)
505"""
return n + 5
to run the test, you import doctest
and run doctest.testmod()
which will run all the doctests in the module. You can also use doctest.testfile("...")
to run all the tests in some other file.
If you check the documentation for doctests you will find ways to make a test expect exceptions, lists, etc -- anything the interpreter would output, plus some wildcards for brevity.
This is a quick way to write tests in Python modules, there isn't a lot of boilerplate code, and IMO it's easier to keep them up to date (the test is right there in the function!). But I also find them a little ugly.