使用pytest在AWS Lambda函数中模拟或修补Boto3 Glue客户端

问题描述

嗨,我正在尝试在lambda函数中模拟/修补glue客户端,但当客户端在处理函数之外定义时,它会失败,但是在客户端在处理函数内部定义时,它会起作用。我猜我需要模拟global / module变量吗?下面是代码片段:

import boto3

session = boto3.session.Session()
glue = session.client('glue')

def handler(event,context):
    glue.start_crawler("test");

测试代码

import pytest

def test_lambda_handler(monkeypatch):
    monkeypatch.setattr(boto3,'session',MockSession)
    response = lambda_function.handler(event={},context={})
    assert response['RunId'] == "success"                

我做错了什么?模拟会话和客户端变量的最佳方法是什么?谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)