amazon-web-services - Stubber 没有 boto3 属性
问题描述
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')
每当我使用 pytest 运行此方法时,都会遇到以下错误:
E AttributeError: 'Stubber' object has no attribute 'describe_stacks'
python/src/example.py:26: AttributeError
关于主要问题是什么的任何见解?
解决方案
我已经找到了解决这个问题的方法。
- 当你调用方法时,不要使用存根。使用实际的 boto3 客户端。
- 将存根方法按照您正在测试的方法的顺序放置,您将调用类似的方法
add_reponse
。例如,如果describe_stacks
调用 beforedelete_stack
,则在测试中添加describe_stacks
beforedelete_stack
;否则,将找不到方法。
推荐阅读
- javascript - 将多个 json 对象合并到一个 json 数组中
- reactjs - 无法导入轮廓的 svg 图标组件材料-ui
- bash - eval $(docker-machine env default) 在 iterm 启动脚本中不起作用
- r - 在 UI 中的输入之间建立依赖关系
- sql - 从 SQL Server 中的重复行中筛选
- python - 找到余弦相似度后对数组进行重构
- amazon-dynamodb - 使用 DynamoDb 回滚?
- php - 设置 CHMOD 777 后 /bin/node 权限被拒绝
- c# - 使用 C# 关闭网络中的特定计算机
- amazon-web-services - 确定 Amazon DynamoDB 表的读取容量单位