【发布时间】:2019-01-29 18:11:28
【问题描述】:
我有以下功能。
def test_download(test_args):
mock = mock_s3()
mock.start()
conn = boto3.resource('s3', region_name='us-west-2')
conn.create_bucket(Bucket=test_args.source_bucket)
s3.Object(test_args.source_bucket, 'testing.txt').put(
Body=open("testing.txt", 'rb'))
handler_client = HandlerClient(test_args)
handler_client.get_s3_file()
使用from moto import mock_s3
我去测试时遇到错误。
def add_auth(self, request):
if self.credentials is None:
> raise NoCredentialsError
E botocore.exceptions.NoCredentialsError: Unable to locate credentials at line
> `conn.create_bucket(Bucket=test_args.source_bucket)`
我尝试过使用装饰器 还有
with moto.mock_s3():
都得到相同的错误。我该如何解决这个问题,以创建一个假的桶,在里面放一个项目。
【问题讨论】:
标签: python amazon-web-services boto3 moto