Is there any way to write unittests
or doctests
for innerfunc
?
def outerfunc():
def innerfunc():
do_something()
return innerfunc()
Only if you provide a way to extract the inner function object itself, e.g.
def outerfunc(calltheinner=True):
def innerfunc():
do_something()
if calltheinner:
return innerfunc()
else:
return innerfunc
If your outer function insists on hiding the inner one entirely inside itself (never letting it percolate outside when properly cajoled to do so), your unit-tests are powerless to defeat this strong bid for extreme and total privacy;-).
This is actually an old open Python issue:
There's a candidate patch (from 2007) that makes doctest find nested functions, but someone probably needs to push this.
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