小编Pra*_*esh的帖子

模拟 boto3 批量写入,用于 python 中的单元测试

我想使用单元测试来测试batch_write方法。

class DataService:
    def __init__(self, table):
        dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
        self.db = dynamodb.Table(self.table)


    def batch_write(self, items):
        with self.db.batch_writer() as batch:
            for item in items:
                batch.put_item(Item=item)
Run Code Online (Sandbox Code Playgroud)

我想模拟batch_writer()。我已经看到使用 mock_open 来模拟文件打开方法。但我真的不明白我可以模拟这个流式batch_writer() 调用吗?

python unit-testing mocking boto3

5
推荐指数
1
解决办法
2551
查看次数

标签 统计

boto3 ×1

mocking ×1

python ×1

unit-testing ×1