我正在编写一个快速类的测试用例,使用boto3从s3中查找/获取密钥。我用摩托在过去的测试伯特(不是3)的代码,但我试图移动这个项目boto3,并运行到一个问题:我该如何测试使用boto3和moto的方法
class TestS3Actor(unittest.TestCase):
@mock_s3
def setUp(self):
self.bucket_name = 'test_bucket_01'
self.key_name = 'stats_com/fake_fake/test.json'
self.key_contents = 'This is test data.'
s3 = boto3.session.Session().resource('s3')
s3.create_bucket(Bucket=self.bucket_name)
s3.Object(self.bucket_name, self.key_name).put(Body=self.key_contents)
错误:
...
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 344, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 314, in _raise_timeout
if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python 2.6
TypeError: __str__ returned non-string (type WantWriteError)
botocore.hooks: DEBUG: Event needs-retry.s3.CreateBucket: calling handler <botocore.retryhandler.RetryHandler object at 0x10ce75310>
它看起来像moto没有正确地模拟出boto3的调用 - 我该如何做这件事?
我没有看到moto中的代码使用boto3。 https://github.com/spulec/moto – mootmoot
确实有一些boto3的支持,但也许不在python2.7? https://github.com/spulec/moto/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+boto3显示很多人都遇到了麻烦。这个问题离我的最近,https://github.com/spulec/moto/issues/474,暗示对HTTPretty的修复将解决它,并且目前正在使用该修补程序的PR,因此希望这可以很快解决-ish。 – user3610360