title: Testing that a method in instance has been called in mock
body: <p>I have this sort of setup where I'm testing a class which is using another class, and I want to mock the latter so I'm only testing the first class itself.</p>
  
  <p><code>nuclear_reactor.py</code>:</p>
  
  <pre><code>class NuclearReactor():
      def __init__(self):
          print "initializing the nuclear reactor"
  
      def start(self):
          print "starting the nuclear reactor"
  </code></pre>
  
  <p><code>nuclear_manager.py</code>:</p>
  
  <pre><code>from nuclear_reactor import NuclearReactor
  
  class NuclearManager():
      def __init__(self):
          print "manager creating the nuclear reactor"
          self.reactor = NuclearReactor()
  
      def start(self):
          print "manager starting the nuclear reactor"
          self.reactor.start()
  </code></pre>
  
  <p><code>test_nuclear_manager.py</code>:</p>
  
  <pre><code>from mock import Mock
  import nuclear_manager
  from nuclear_manager import NuclearManager
  
  def test():
      mock_reactor = nuclear_manager.NuclearReactor = Mock()
      nuke = NuclearManager()
      nuke.start()
      nuke.start()
      print mock_reactor.mock_calls
      print mock_reactor.start.call_count
  
  test()
  </code></pre>
  
  <p>What I'd like to test is that <code>NuclearReactor.start</code> is called,
  but when I run this I get:</p>
  
  <pre><code>manager creating the nuclear reactor
  manager starting the nuclear reactor
  manager starting the nuclear reactor
  [call(), call().start(), call().start()]
  0
  </code></pre>
  
  <p>Which I totally understand since <code>start</code> is an attribute of the instance and not of the class, and I could parse the <code>mock_calls</code>, but isn't there a better way to check that the call of an instantiated mocked class is made?</p>
  
  <p>I could use dependency injection in <code>NuclearManager</code> to pass a mock <code>NuclearReactor</code>, but I'm thinking there would be an alternative way using just mock.</p>