This code runs, does not error, but does not mock out the function like I would like. Why not? Also, clearly, these functions are not "side effects", they are pure functions, but AFAIK, that is the syntax used to mock out a function using the standard Python mocking library.
# mocking test
from mock import mock
def local_f(a, b):
print "default local_f(%d,%d)" % (a, b)
return a + b
def local_f2(a, b):
print "local_f2(%d,%d)" % (a, b)
return a * b
def go():
print "(before) testing simple_f: %s" % local_f(3, 4)
with mock.patch('mock_test.local_f',
side_effect=local_f2) as mock_function_obj:
print "type(mock_function_obj) = %s" % type(mock_function_obj)
print "(with) testing simple_f: %s" % local_f(3, 4)
print "(after) testing simple_f: %s" % local_f(3, 4)
if __name__ == "__main__":
go()