title: Python Kafka mocking return type of Kafka Consumer
body: <p>I want to test a script when I use <code>kafka-python</code> package. I want to test type of return object for  function</p>
  <pre><code>def _get_kafka_consumer() -&gt; KafkaConsumer:
      consumer = KafkaConsumer(bootstrap_servers=_KAFKA_BOOTSTRAP_SERVICE,
                               auto_offset_reset='earliest')
      consumer.subscribe([_KAFKA_TOPIC_INPUT])
      return consumer
  </code></pre>
  <p>My test class looks like</p>
  <pre><code>class TestVoiceToText(unittest.TestCase):
  
      def test_get_kafka_consumer_output_type(self):
          result = _get_kafka_consumer()
          self.assertIsInstance(result, KafkaConsumer)
  </code></pre>
  <p>and of course it does not pass because there is no Kafka Cluster running so <code>KafkaConsumer</code> cannot be created. How can I mock that returning of <code>KafkaConsumer(...)</code> is of type <code>KafkaConsumer</code> without actual need of calling the actual constructor?</p>