title: Pytest with mock/pytest-mock
body: <p>For some reason I cannot get mock.patch to work in any scenario when using Pytest.  It simply doesn't do the patching.  Am I using it incorrectly or is something messed up with my configuration?    </p>
  
  <p><strong>base.py</strong></p>
  
  <pre><code>def foo():
      return 'foo'
  
  def get_foo():
      return foo()
  </code></pre>
  
  <p><strong>test_base.py</strong></p>
  
  <pre><code>import pytest
  import mock
  from pytest_mock import mocker
  
  from base import get_foo
  
  @mock.patch('base.foo') 
  def test_get_foo(mock_foo):
      mock_foo.return_value = 'bar'
      assert get_foo() == 'bar'
  
  def test_get_foo2(mocker):
      m = mocker.patch('base.foo', return_value='bar')
      assert get_foo() == 'bar'
  
  def test_get_foo3():
      with mock.patch('base.foo', return_value='bar') as mock_foo:
          assert get_foo() == 'bar'
  </code></pre>
  
  <p><strong>pytest results</strong></p>
  
  <pre><code>============================================================= test session starts =============================================================
  platform linux2 -- Python 2.7.13, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
  rootdir: /projects/git/ABC/query, inifile:
  plugins: mock-1.6.0
  collected 13 items 
  
  test_base.py .....FFF.....
  
  ================================================================== FAILURES ===================================================================
  ________________________________________________________________ test_get_foo _________________________________________________________________
  
  mock_foo = &lt;MagicMock name='foo' id='140418877133648'&gt;
  
      @mock.patch('base.foo')
      def test_get_foo(mock_foo):
          mock_foo.return_value = 'bar'
  &gt;       assert get_foo() == 'bar'
  E       AssertionError: assert 'foo' == 'bar'
  E         - foo
  E         + bar
  
  test_base.py:67: AssertionError
  ________________________________________________________________ test_get_foo2 ________________________________________________________________
  
  mocker = &lt;pytest_mock.MockFixture object at 0x7fb5d14bc210&gt;
  
      def test_get_foo2(mocker):
          m = mocker.patch('base.foo', return_value='bar')
  &gt;       assert get_foo() == 'bar'
  E       AssertionError: assert 'foo' == 'bar'
  E         - foo
  E         + bar
  
  test_base.py:71: AssertionError
  ________________________________________________________________ test_get_foo3 ________________________________________________________________
  
      def test_get_foo3():
          with mock.patch('base.foo', return_value='bar') as mock_foo:
  &gt;           assert get_foo() == 'bar'
  E           AssertionError: assert 'foo' == 'bar'
  E             - foo
  E             + bar
  
  test_base.py:75: AssertionError
  </code></pre>