title: Monkey patch a function in a module for unit testing
body: <p>I have the following method in a module that calls another method imported from another module:</p>
  
  <pre><code>def imported_function():
      do_unnecessary_things_for_unittest()
  </code></pre>
  
  <p>The actual method that needs to be tested, imports and uses the above function:</p>
  
  <pre><code>from somewhere import imported_function
  
  def function_to_be_tested():
      imported_function()
      do_something_more()
      return 42
  </code></pre>
  
  <p>The inner calls and related calculations inside <strong>imported_function</strong> are not important and they are not what I want to test so I just want to skip them while testing the actual function <strong>function_to_be_tested</strong>.</p>
  
  <p>Thus, I tried to monkey patch the module named <strong>somewhere</strong> inside the test method but no luck.</p>
  
  <pre><code>def test_function_to_be_tested(self):
      import somewhere
      somewhere.__dict__['imported_function'] = lambda : True
  </code></pre>
  
  <p>The question is, how can I monkey patch a method of a module while testing so that it will not be called during the test phase?  </p>