How do you unit test a nested function?

e1i45 picture e1i45 · Nov 28, 2012 · Viewed 13.4k times · Source

How would you unit test the nested function f1() in the following example?

def f():
    def f1():
       return 1
    return 2

Or should functions that need testing not be nested?

Answer

alemangui picture alemangui · Nov 28, 2012

There is a similar question in this link. But short answer: you can't access an inner function from an outer element.

For testing purposes, maybe an alternative would be to change the inner function for a private outer one?