-
Notifications
You must be signed in to change notification settings - Fork 108
[BUG] It is not possible to unit test a Python timer function #737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] It is not possible to unit test a Python timer function #737
Comments
Try passing True or False to the constructor to set past_due. Example here: https://github.com/Azure/azure-functions-python-library/blob/8ef845cd8f688c9aba5ed7b96f0951cba4856e12/azure/functions/timer.py#L35 |
Thanks, this worked. Can I suggest that this is added to the docs as an example alongside the others? |
That wasn't working for me anymore, in the end I created a class with the past_due attribute set to True, and that did the trick (also on stack overflow): 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) |
Hi everyone, sorry for the delay on this. We're currently working on a fix that will allow for unit testing of TimerRequest without the additional workarounds. You'll be able to create a TimerRequest object like this: I've updated our wiki to show specifically the TimerRequest example. With |
Azure provides documentation for unit testing HTTP and Queue Python functions. This is done by creating a mock QueueMessage or HTTPRequest. However, there is no documentation for creating a unit test for Timer functions.
There is a TimerRequest class, but creating a new instance of it fails with the following error:
Having posted on StackOverflow to ask about the correct approach for this e.g. if I want to test behaviour of a function which has
past_due
set, but had no answers, I'm opening this bug to request that Python functions allow unit testing.The text was updated successfully, but these errors were encountered: