testingdebuggingprofilingand tuning it should be noted that the unittest module contains large number of advanced customization options for grouping testscreating test suitesand controlling the environment in which tests run these features are not directly related to the process of writing tests for your code (you tend to write testing classes as shown independently of how tests actually get executedconsult the documentation at library/unittest html for more information on how to organize tests for larger programs the python debugger and the pdb module python includes simple command-based debugger which is found in the pdb module the pdb module supports post-mortem debugginginspection of stack framesbreakpointssingle-stepping of source linesand code evaluation there are several functions for invoking the debugger from program or from the interactive python shell run(statement [globals [locals]]executes the string statement under debugger control the debugger prompt will appear immediately before any code executes typing 'continuewill force it to run globals and locals define the global and local namespacesrespectivelyin which the code runs runeval(expression [globals [locals]]evaluates the expression string under debugger control the debugger prompt will appear before any code executesso you will need to type 'continueto force it to execute as with run(on successthe value of the expression is returned runcall(function [argument]calls function within the debugger function is callable object additional arguments are supplied as the arguments to function the debugger prompt will appear before any code executes the return value of the function is returned upon completion set_trace(starts the debugger at the point at which this function is called this can be used to hard-code debugger breakpoint into specific code location post_mortem(tracebackstarts post-mortem debugging of traceback object traceback is typically obtained using function such as sys exc_info(pm(enters post-mortem debugging using the traceback of the last exception of all of the functions for launching the debuggerthe set_trace(function may be the easiest to use in practice if you are working on complicated application but you have detected problem in one part of ityou can insert set_trace(call into the code and simply run the application when encounteredthis will suspend the program and go directly to the debugger where you can inspect the execution environment execution resumes after you leave the debugger lib fl ff