title: Mocking functions in python called from a dictionary
body: <p>I have a problem with the code below. I would like to mock the functions in different file for unit testing in the FUNCTION_MAPPING part.</p>
  <pre><code>import module.module2 as module_name
  
  FUNCTION_MAPPING = {
  1: module_name.foo,
  2: module_name.foo2,
  3: module_name.foo3
  }
  
  def my_func(number):
      function_call = FUNCTION_MAPPING[number]
      result = function_call()
      return result
  </code></pre>
  <p>For some reason I can not mock those functions. I have tried every possible way that i had knowledge about. If possible i would like not to change the code above.</p>
  <p>foo, foo2 and foo3 inner code can be anything print(1), print(2) etc</p>
  <p>Code of the unit test:</p>
  <pre><code>@patch(&quot;module_of_the_code_above.module_name.foo&quot;,return_value=&quot;Test&quot;)
  def test_my_func(self,mocked_foo):
      result = my_func(1)
      nose_tools.assert_equal(result,&quot;Test&quot;)
  </code></pre>