I am trying to assign a function to another function the left hand side of the assignment is available to me as a String. For example the body of the method I am looking for is
def change_function_defintion(name_of_function = 'module1.function1'
, function_object):
# Can I do eval(name_of_function) = function_object ? will that work?
pass
Questions:
- How do I achieve this? Obviously if I call the above method and then call the module.function1 I expect the new function to be picked up.
- I am doing this in the context of unit testing i.e, Mock several functions, run the test and then basically "unmock" them. Are there any problems with the said approach?