Search code examples
amazon-web-servicesaws-cloudformationboto3stub

Stubber has no boto3 attribute


    self.cf_client = boto3.client('cloudformation')
    self.cf_client_stubber = Stubber(self.cf_client)

    print(f" cc {type(self.cf_client_stubber)}")

    self.cf_client_stubber.add_response("describe_stacks", self.cf_describe_response,
                                        self.cf_describe_params)
    self.cf_client_stubber.activate()

    stackList = self.cf_client_stubber.describe_stacks(StackName=self.cf_stack_name, NextToken='xyz')

   

whenever I run this method with pytest, I encounter the following error:

E           AttributeError: 'Stubber' object has no attribute 'describe_stacks'

python/src/example.py:26: AttributeError

Any insight as to what the main problem would be?


Solution

  • I have found the solution to this problem.

    1. When you are calling the method, don't use the stubber. Use the actual boto3 client.
    2. Put the stubber methods in the order of which the method you are testing methods you will invoke like add_reponse. For example, if describe_stacks is called before delete_stack, then in the test add describe_stacks before delete_stack; otherwise, the methods will not be found.