title: How do I mock a class in a Python unit test?
body: <p>I have a class:</p>
  
  <pre><code>class A:
      __init__(self):
          self.b = B()
  
     def is_authorized(self)
        name = self.b.get_name()
  
        if name == 'admin':
            return True
        else:
            return False
  </code></pre>
  
  <p>I'd like to write a unit test to test the <code>is_authorized</code> method. The problem is that it requires an instance of the <code>B</code> class which is very complicated to construct in isolation as it requires network connections and other stuff. How can I mock this class and provide something that just has the <code>get_name</code> method. So that I can create the <code>A</code> class and test the method.</p>