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?
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?
You don't, because you can't.
You will have to either limit your unit testing to the outer function, or you move the inner function elsewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With