title: mock xmlrpc.client method python
body: <p>I am in the process of learning unit testing, however I am struggling to understand how to mock functions for unit testing.  I have reviewed many how-to's and examples but the concept is not transferring enough for me to use it on my code.  I am hoping getting this to work on a actual code example I have will help.</p>
  
  <p>In this case I am trying to mock isTokenValid.</p>
  
  <p>Here is example code of what I want to mock.</p>
  
  <pre><code>&lt;in library file&gt;
  
  import xmlrpc.client as xmlrpclib   
  
  class Library(object):
      def function:
          #...
          AuthURL = 'https://example.com/xmlrpc/Auth'
          auth_server = xmlrpclib.ServerProxy(AuthURL)
          socket.setdefaulttimeout(20)
          try:
              if pull == 0:
                  valid = auth_server.isTokenValid(token)
          #...
  </code></pre>
  
  <p>in my unit test file I have </p>
  
  <pre><code>import library
  
  class Tester(unittest.TestCase):
      @patch('library.xmlrpclib.ServerProxy')
      def test_xmlrpclib(self, fake_xmlrpclib):
          assert 'something'
  </code></pre>
  
  <p>How would I mock the code listed in 'function'?   Token can be any number as a string and valid would be a int(1)</p>