modules one really simple way to do this is to execute the examples in the docstrings and make sure that they produce the expected results this can be done by adding just three lines at the end of the module' py fileif __name__ ="__main__"import doctest doctest testmod(whenever module is imported python creates variable for the module called __name__ and stores the module' name in this variable module' name is simply the name of its py file but without the extension so in this examplewhen the module is imported __name__ will have the value "textutil"and the if condition will not be metso the last two lines will not be executed this means that these last three lines have virtually no cost when the module is imported whenever py file is run python creates variable for the program called __name__ and sets it to the string "__main__so if we were to run textutil py as though it were programpython will set __name__ to "__main__and the if condition will evaluate to true and the last two lines will be executed the doctest testmod(function uses python' introspection features to discover all the functions in the module and their docstringsand attempts to execute all the docstring code snippets it finds running module like this produces output only if there are errors this can be disconcerting at first since it doesn' look like anything happened at allbut if we pass command-line flag of -vwe will get output like thistryingis_balanced("(python (is (not (lisp))))"expectingtrue ok tryingsimplify(disemvoweled "delete="aeiou"expecting'dsmvwldok items passed all tests tests in __main__ tests in __main__ is_balanced tests in __main__ shorten tests in __main__ simplify tests in items passed and failed test passed