title: Unable to Use pytest-mock in pytest to Verify Construction and Instance Method Calls Simultaneously
body: <p>To start, I'm using the pytest-mock and pytest packages to test a software project that I'm working on.</p>
  
  <p>I have a situation where I'm testing a class in a module and trying to mock out a composite object that it instantiates from its <code>__init__</code> method. When I do this, I am able to assert that the <code>__init__</code> method is properly called, but when I try to assert that an instance method is called, I get an assertion error.</p>
  
  <p>When I debug pytest by passing the <code>--pdb</code> option to it, I verify by checking the <code>MagicMock()</code> object's <code>.method.called</code> property that it "wasn't" called, but then when I check the <code>MagicMock()</code> object's <code>.method_calls</code> property, I see that it was in fact called.</p>
  
  <p>Here's a simple example to show what I mean:</p>
  
  <h3>test.py</h3>
  
  <pre><code>import module
  
  def test_Calling(mocker):
      mocker.patch('module.Called', autospec=True)
  
      module.Calling('argument')
  
      module.Called.assert_called_once_with('argument')
      module.Called.check_me.assert_called_once()
  </code></pre>
  
  <h3>module.py</h3>
  
  <pre><code>class Calling(object):
      def __init__(self, argument):
          called_instance = Called(argument)
          called_instance.check_me()
  
  class Called(object):
      def __init__(self, argument):
          pass
  
      def check_me(self):
          pass
  </code></pre>
  
  <p>And here's the pytest/pdb session:</p>
  
  <pre><code>(venv) C:\pytest-issue&gt;pytest --pdb test.py
  ============================= test session starts =============================
  platform win32 -- Python 2.7.12, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
  rootdir: C:\pytest-issue, inifile:
  plugins: mock-1.5.0
  collected 1 items
  
  test.py F
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; traceback &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  
  mocker = &lt;pytest_mock.MockFixture object at 0x000000000431B2E8&gt;
  
      def test_Calling(mocker):
          mocker.patch('module.Called', autospec=True)
  
          module.Calling('argument')
  
          module.Called.assert_called_once_with('argument')
  &gt;       module.Called.check_me.assert_called_once()
  
  test.py:9:
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  
  _mock_self = &lt;MagicMock name='Called.check_me' spec='instancemethod' id='70367608'&gt;
  
      def assert_called_once(_mock_self):
          """assert that the mock was called only once.
          """
          self = _mock_self
          if not self.call_count == 1:
              msg = ("Expected '%s' to have been called once. Called %s times." %
                     (self._mock_name or 'mock', self.call_count))
  &gt;           raise AssertionError(msg)
  E           AssertionError: Expected 'check_me' to have been called once. Called 0 times.
  
  venv\lib\site-packages\mock\mock.py:915: AssertionError
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; entering PDB &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  &gt; c:\pytest-issue\venv\lib\site-packages\mock\mock.py(915)assert_called_once()
  -&gt; raise AssertionError(msg)
  (Pdb) up
  &gt; c:\pytest-issue\test.py(9)test_Calling()
  -&gt; module.Called.check_me.assert_called_once()
  (Pdb) module.Called.method_calls
  [call().check_me()]
  (Pdb) module.Called.check_me.called
  False
  </code></pre>
  
  <p>For the life of me, I'm not sure what I'm doing wrong. In this circumstance, do I need to assert <code>.Called.method_calls</code>? If so, that looks like I would have to put a lot of logic into my tests, which is not desirable.</p>