Azure provide documentation for unit testing HTTP and Queue Python functions 。这是通过创建一个模拟 QueueMessage 来完成的或HTTPRequest 。但是,没有为 Timer functions 创建单元测试的文档。 .
有一个TimerRequest class ,但创建它的新实例失败并出现以下错误:
req = func.TimerRequest()
TypeError: Can't instantiate abstract class TimerRequest with abstract methods past_due
为 Python Azure 计时器函数创建单元测试的正确方法是什么?
最佳答案
接受的答案不再对我有用,最后我创建了一个类,并将 Past_due 属性设置为 True,这就达到了目的:
import unittest
from azure.functions import TimerRequest
from my_func import main
class MockTimer():
def __init__(self):
self.past_due = True
class TestFunction(unittest.TestCase):
def test_my_function(self):
timer = MockTimer()
resp = main(timer)
关于python - 对 Python Azure 计时器函数进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63355115/