如何检查botocore配置的max_attempts是否有效

时间:2019-07-04 11:54:37

标签: python amazon-s3 boto3 moto

问题是我想编写一些测试来检查使用配置选项retries=dict(max_attempts=10)创建的s3客户端在引发异常或其他任何事件之前是否真的尝试了10次。但是我对如何做到没有很强的了解。

我使用过mock_s3,并尝试了使用monkeypatching所需的s3方法的moto_server,但没有成功。

首先运行moto_server

moto_server s3 --port 4567

def test_delete():
   client = boto3.client("s3", config=Config(retries=dict(max_attempts=10)), endpoint_url="http://localhost:4567")
   client.create_bukect(Bucket="bucket_name")
   client.put_object(Bucket="bucket_name", Key="file_name", Body="file_content".encode("utf-8"))
   client.delete_object(Bucket="bucket_name", Key="wrong_file_name")

我希望在运行moto_server的console中收到有关错误文件名的10条记录。是否有测试重试的正确方法,您能否分享自己的想法?

0 个答案:

没有答案