For quick and easy testing, you may need to doctests .
To write tests, you put 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 subsidies in the module. You can also use doctest.testfile("...") to run all the tests in some other file.
If you check the documentation for doctrines , you will find ways to make tests the expected exceptions, lists, etc. - all that the interpreter displays, plus a few wildcards for brevity.
This is a quick way to write tests in Python modules, there is not much template code, and IMO is easier to keep them up to date (the test is right there in the function!). But I also find them a little ugly.
source share