title: How to mock a function defined in a module of a package?
body: <p>I've got a following structure:</p>
  
  <pre><code>|-- dirBar
  |   |-- __init__.py
  |   |-- bar.py
  |-- foo.py
  `-- test.py
  </code></pre>
  
  <p>bar.py</p>
  
  <pre><code>def returnBar():
      return 'Bar'
  </code></pre>
  
  <p>foo.py</p>
  
  <pre><code>from dirBar.bar import returnBar
  
  def printFoo():
      print returnBar()
  </code></pre>
  
  <p>test.py</p>
  
  <pre><code>from mock import Mock
  
  from foo import printFoo
  from dirBar import bar
  
  bar.returnBar = Mock(return_value='Foo')
  
  printFoo()
  </code></pre>
  
  <p>the result of <code>python test.py</code> is <code>Bar</code>.</p>
  
  <p>How to mock the <code>printBar</code> to make it return <code>Foo</code> so that <code>printFoo</code> will print it?</p>
  
  <p>EDIT: Without modifying any other file that <code>test.py</code></p>