首页 > 解决方案 > 需要通过 mock 在本地测试 Python Google Cloud Function

问题描述

我是 Python3 中云函数和模拟测试的新手。

我编写了一个基本的 python 谷歌云函数来将数字字符串存储到谷歌云存储桶中。

from google.cloud import storage
import uuid
import os 

file_name = uuid.uuid4().hex
file_content = os.urandom(32)

cloudStorage = storage.Client()
my_folder_name = 'random' + '/' + file_name
            
bucket = cloudStorage.bucket('TestBucket')
folder = bucket.blob(my_folder_name)
folder.upload_from_string( file_content , content_type="text/plain") 

欣赏任何想法或方法来编写单元测试脚本并通过模拟在本地机器上执行它?

标签: python-3.xunit-testingmockinggoogle-cloud-functionsgoogle-cloud-storage

解决方案


推荐阅读