【问题标题】:How to mock a s3 object in python?如何在 python 中模拟 s3 对象?
【发布时间】:2021-09-09 12:00:12
【问题描述】:

在我的代码中,有一种方法可以从 s3 存储桶中获取 csv 文件。我需要在我的测试文件中模拟该对象。下面是源码函数

s3 = boto3.client('s3')
def method():
    ...
    obj = s3.get_object(bucket, key)
    csv_content = obj['Body'].read().decode('utf-8')
    ...

我需要在“obj”之上进行模拟。我需要使用单独的模块吗?请提出你的想法

【问题讨论】:

    标签: python-3.x python-unittest python-unittest.mock


    【解决方案1】:

    Moto 是 python 中用来模拟 S3 和其他一些 AWS 服务的常用包。

    https://github.com/spulec/moto

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 2022-10-17
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      相关资源
      最近更新 更多