title: Mock method globally with unittest.mock.patch
body: <p>I'm trying to mock a method that is called by another method in a separate module. Specifically, I would like the call to <code>foo</code> in bar.py to be replaced with a call to <code>mock_foo</code>:</p>
  <p>foo.py</p>
  <pre><code>def foo():
      return 'foo'
  </code></pre>
  <p>bar.py</p>
  <pre><code>from foo import foo
  
  def bar.py():
      return foo()
  </code></pre>
  <p>test.py</p>
  <pre><code>from bar import bar
  
  def mock_foo():
      return 'mock_foo'
  
  def testmethod():
      with patch('foo.foo', mock_foo):
          print(bar())  
          # Expected output:'mock_foo'
  
  </code></pre>
  <p>The <code>patch</code> approach above doesn't work. Is this possible to do with the mock library? If so, how should I modify test.py?</p>