Accessing nested functions for testing

Chad Netzer cnetzer at mail.arc.nasa.gov
Tue May 20 18:50:31 EDT 2003


On Tue, 2003-05-20 at 15:23, Erik Max Francis wrote:

> I think there's a higher-level issue here; if you have a true nested
> function, then that inner function has scope entirely within the
> function itself.
> 
> So the test cases should handle the high-level behavior of the outer
> function; they shouldn't care whether there's an inner function in there
> (whether or not they can get access to it) because it's an
> implementation detail of that outer function.

Oh, certainly true.  However, for testing purposes it would have been
useful to test the inner components separately, since I wanted to verify
them separately (they became sub-functions simply because I refactored
them out from a larger function).  It was easiest to fix the behavior of
the outer level function, by testing each sub-function.  In the end, it
was just as easy to bring them to the outer scope, and test them there.

If it were straightforward to execute sub-functions, I could provide a
harness for each that ran them from a conforming namespace.  However, it
seems to be the case that any nested function that is complex enough to
NEED to be tested, is probably important enough to make non-nested in
anticipation of reusing it. So, practically, it has become a non-issue
issue.


-- 

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)






More information about the Python-list mailing list