title: Pytest Mocking Other class objects in Main class in Python with Kafka
body: <p>I am new to doing testing using Pytest and I am trying to test a class which has a constructor that creates objects of different classes.
  I am having a trouble to mock these three objects. As the method in my class uses methods from these classes using the objects created in constructor.</p>
  <p>Feature.py</p>
  <pre><code>class Feature:
      def __init__(self):
          self.kafka_consumer = KafkaConsumer()
          self.kafka_producer = KafkaProducer()
          self.production = Production(self.kafka_consumer.start)
          self.messageGenerator = MessageGenerator()
          self.generate()
  
      def generate(self):
          while(self.kafka_consumer.isReady):
              try:
                  // Kafka Code
      def messageGenerator(self):
          // Generating Message and send from Kafka
  </code></pre>