Reputation: 2851
I did:
mocker.patch('boto3.client.upload_fileobj')
but this does not work. I can't seem to get the path right but this is how it's used so I don't understand. Anyone mock this call before?
Upvotes: 1
Views: 1476
Reputation: 745
The correct module path is "boto3.s3.inject.upload_fileobj":
import mock
import boto3
with mock.patch('boto3.s3.inject.upload_fileobj'):
s3 = boto3.resource('s3')
s3.Bucket('my-bucket').upload_fileobj(open('file.png', 'rb'), 'filename')
However, in many situations I think you'll find mocking AWS operations to be much easier with Moto: https://pypi.org/project/moto/
Upvotes: 3