Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test a function inside a function?

If I have a function like this:

def any_function(type_name, field_name):
    def another_function(name):
        ...

How would I go about testing any_function?

In case I used the wrong definition of testing, I mean by writing print(any_function(...))

like image 478
Tyler Avatar asked Mar 18 '23 00:03

Tyler


1 Answers

You wouldn't test an inner function. You'd just test the functionality of the outer function; the inner function is an implementation detail, not the API presented by the unit. You'd normally use an inner function to produce a closure, making the inner function dependent on the scope.

Now, if the inner function is returned by the outer, test that return value, like you would the product of any function.

If the inner function is independent and requires tests of its own, you shouldn't be nesting it.

like image 123
Martijn Pieters Avatar answered Mar 31 '23 07:03

Martijn Pieters