如何使用事件网格触发器对 Python 中的 azure 函数进行单元测试

How to unit test an azure function in Python using event grid trigger

我在 Python 中使用事件网格触发器编写了一个 azure 函数 问题是我想编写单元测试,但我找不到如何从事件网格模拟事件的示例。

知道如何为事件网格创建单元测试吗?

万分感谢

测试使用事件网格触发器的 Azure Functions 是在本地 运行 Function App,然后在云中获取 Azure 以在本地计算机上调用函数 运行ning。

示例: 你要使用 Event Grid to improve the reliability and responsiveness of Blob Storage processing. Check the documentation建议使用ngrok。现在,当将 blob 添加到云中的容器时,将通过 ngrok.

调用开发机器上的本地 运行ning 函数

有一个更简单的解决方案,允许您在本地调用事件网格触发函数。

这种方法完全绕过了事件网格,因此它不能替代适当的端到端测试,它更像是一种开发时测试和调试工具。

手动 运行 非 HTTP 触发的 Azure Functions

您可以通过特殊 HTTP 端点.

手动触发 non HTTP-triggered 函数(例如定时器触发或事件网格触发函数)

端点的格式为: {host}/admin/functions/{function name}

Note: If you want to test after deployment you have to add the logs to know the detailed information.

参考blog了解更多信息