e1i45 e1i45 - 11 months ago 57
Python Question

Python: How do you unit test a nested function?

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 Source

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?