I am trying to make fun of one specific boto3 function. My Cleanup module imports boto3. Cleanup also has a cleaner class. During init, the cleaner creates an ec2 client:
self.ec2_client = boto3.client('ec2')
I want to make fun of the ec2 client method: desribe_tags (), which python says:
<bound method EC2.describe_tags of <botocore.client.EC2 object at 0x7fd98660add0>>
The longest I got was importing the botocore into a test file and trying:
mock.patch(Cleaner.botocore.client.EC2.describe_tags)
which fails:
AttributeError: 'module' object has no attribute 'EC2'
How do I make fun of this method?
The cleanup looks like this:
import boto3 class cleaner(object): def __init__(self): self.ec2_client = boto3.client('ec2')
An ec2_client object is one that has a desribe_tags () method. This is a botocore.client.EC2 object, but I never directly import botocores.
source share