title: mocking a method with another reusable method with arguments in python
body: <p>I have an instance method that I want to test using mock. I am trying to substitute one of the method in this instance class with another method that takes arguments. </p>
  
  <p>class to be test: </p>
  
  <pre class="lang-py prettyprint-override"><code>class ClassToTest():
      def compute(self):
          result = self._get_xml()
          return result
  
      def _get_xml(self):
          #get xml here
          return xml    
  </code></pre>
  
  <p>The test file:</p>
  
  <pre class="lang-py prettyprint-override"><code>from mock import patch
  class ClassTest():
  
      @patch('classToTest._get_xml', _get_fake_xml)
      def computetest(self):
          test = ClassToTest()
          toassert = test.compute()
  
          #assert whatever
          #self.assert(...)
  
      def _get_fake_xml(self, objects, filename):
          py_file = os.path.abspath(__file__)
          py_dir = os.path.dirname(py_file)
          xml_file = os.path.join(py_dir, filename)
          xml_tree = objectify.parse(xml_file)
          return xml_tree.getroot()
          return xml 
  </code></pre>
  
  <p>Now how can I add the arguments for _get_fake_xml method in the patch</p>
  
  <p>I have tried :
  </p>
  
  <pre><code>@patch('classToTest._get_xml', _get_fake_xml(mock.Mock(), 'filenam.xml'))
  </code></pre>
  
  <p>But that didn't work. Then I tried to make filename as a global variable but I get the following error:</p>
  
  <p>self.filename does not exist in ClassToTest instance.</p>
  
  <p>Basically I want to be able to reuse _get_fake_xml with any other filename.</p>
  
  <p>Any suggestion?</p>