如何修补从另一个模块导入的函数
How to patch a function imported from another module
无法修补函数。
我正在尝试在我的测试函数中修补来自另一个模块的函数。但是我做不到。
response.py
import boto3
lambda = boto3.client('lambda')
def response(event,context):
s = boto3.client('s')
test_response.py
class lambda_handler(unittest.Testcae):
@patch('response.boto3')
test_handler():
#doing the necessary assertions.
但是上面提到的那个给了我以下错误
botocore.exceptions.NoRegionError: You must specify a region.
显示在响应函数外声明的 boto3.client
的错误。
请帮我解决这个问题。
首先修正这里的错字 class lambda_handler(unittest.Testcae): on Testcase
另外 boto3.client
需要一个参数 region
。即:
import boto3
lambda = boto3.client('lambda', region_name='us-west-2')
def response(event,context):
s = boto3.client('s')
无法修补函数。
我正在尝试在我的测试函数中修补来自另一个模块的函数。但是我做不到。
response.py
import boto3
lambda = boto3.client('lambda')
def response(event,context):
s = boto3.client('s')
test_response.py
class lambda_handler(unittest.Testcae):
@patch('response.boto3')
test_handler():
#doing the necessary assertions.
但是上面提到的那个给了我以下错误
botocore.exceptions.NoRegionError: You must specify a region.
显示在响应函数外声明的 boto3.client
的错误。
请帮我解决这个问题。
首先修正这里的错字 class lambda_handler(unittest.Testcae): on Testcase
另外 boto3.client
需要一个参数 region
。即:
import boto3
lambda = boto3.client('lambda', region_name='us-west-2')
def response(event,context):
s = boto3.client('s')