Amazon web services Stubber没有boto3属性
每当我使用pytest运行此方法时,都会遇到以下错误:Amazon web services Stubber没有boto3属性,amazon-web-services,amazon-cloudformation,boto3,stub,Amazon Web Services,Amazon Cloudformation,Boto3,Stub,每当我使用pytest运行此方法时,都会遇到以下错误: 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_s
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')
对主要问题有什么见解吗?我已经找到了这个问题的解决方案
add\u response
。例如,如果在delete\u stack
之前调用descripe\u stack
,则在测试中,在delete\u stack
之前添加descripe\u stack
;否则,将找不到方法我将添加一个示例,因为接受的答案没有 就在这个时候 请注意,使用
s3
客户端发出请求,而不是stuber
E AttributeError: 'Stubber' object has no attribute 'describe_stacks'
python/src/example.py:26: AttributeError
如果您试图使用stuber发出请求,您将得到上述错误
AttributeError:“Stubber”对象没有属性
您能否在实现您提到的#1和#2之后提供工作代码?我遇到了同样的问题
service_response = s3.list_objects(Bucket='test-bucket')
import datetime
import botocore.session
from botocore.stub import Stubber
s3 = botocore.session.get_session().create_client('s3')
stubber = Stubber(s3)
response = {
'IsTruncated': False,
'Name': 'test-bucket',
'MaxKeys': 1000, 'Prefix': '',
'Contents': [{
'Key': 'test.txt',
'ETag': '"abc123"',
'StorageClass': 'STANDARD',
'LastModified': datetime.datetime(2016, 1, 20, 22, 9),
'Owner': {'ID': 'abc123', 'DisplayName': 'myname'},
'Size': 14814
}],
'EncodingType': 'url',
'ResponseMetadata': {
'RequestId': 'abc123',
'HTTPStatusCode': 200,
'HostId': 'abc123'
},
'Marker': ''
}
expected_params = {'Bucket': 'test-bucket'}
stubber.add_response('list_objects', response, expected_params)
stubber.activate()
service_response = s3.list_objects(Bucket='test-bucket')
assert service_response == response