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