title: How to throw exception from mocked instance's method?
body: <p>This demo function I want to test is pretty straight forward. </p>
  
  <pre><code>def is_email_deliverable(email):
      try:
          return external.verify(email)
      except Exception:
          logger.error("External failed failed")
          return False
  </code></pre>
  
  <p>This function uses an <code>external</code> service which I want to mock out. </p>
  
  <p>But I can't figure out how to throw an <code>exception</code> from <code>external.verify(email)</code>  i.e. how to force the <code>except</code> clause to be executed.</p>
  
  <p>My attempt:</p>
  
  <pre><code>@patch.object(other_module, 'external')
  def test_is_email_deliverable(patched_external):    
      def my_side_effect(email):
          raise Exception("Test")
  
      patched_external.verify.side_effects = my_side_effect
      # Or,
      # patched_external.verify.side_effects = Exception("Test")
      # Or,
      # patched_external.verify.side_effects = Mock(side_effect=Exception("Test"))
  
      assert is_email_deliverable("some_mail@domain.com") == False
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/40736292/python-mock-raise-exception">This</a> question claims to have the answer, but didn't work for me. </p>