Exhaustive Unit Testing

Terry Reedy tjreedy at udel.edu
Fri Nov 28 00:47:18 CET 2008

bearophileHUGS at lycos.com wrote:
> Emanuele D'Arrigo:
>> I can fragment the code of the original method into one public method and a few private support methods.<
> Python also support nested functions, that you can put into your
> method. The problem is that often unit test functions aren't able to
> test nested functions.
> A question for other people: Can Python change a little to allow
> nested functions to be tested? I think this may solve some of my
> problems.

The problem is that inner functions do not exist until the outer 
function is called and the inner def is executed.  And they cease to 
exist when the outer function returns unless returned or associated with 
a global name or collection.

A 'function' only needs to be nested if it is intended to be different 
(different default or closure) for each execution of its def.

More information about the Python-list mailing list