0

我目前正在学习如何为 boto3 编写单元测试

我正在尝试遵循moto 文档并为单元测试编写了几行代码,但它给了我错误:

  @mock_s3
    def test_upload_to_s3(self):
        conn = boto3.resource('s3')
        # We need to create the bucket since this is all in Moto's 'virtual' AWS account
        conn.create_bucket(Bucket='mybucket')

        instance = s3_upload.upload_to_s3('test.csv', 'mybucket',
                                          'test.csv')
        instance.upload_to_s3()

        body = conn.Object(test.csv).get()['Body'].read().decode("utf-8")

        assert body == 'test.csv'


if __name__ == '__main__':
    unittest.main()

错误:AttributeError: 'NoneType' object has no attribute 'upload_to_s3'

我已经为此苦苦挣扎了一整天,有人可以给我一个例子或一些提示,在此先感谢。

4

0 回答 0