For testing flows: <https://docs.prefect.io/core/i...
# prefect-community
b
For testing flows: https://docs.prefect.io/core/idioms/testing-flows.html , when you run anything with
flow.run()
do you need to have the prefect server up? As my test just seems to hang once it hits that part.
👀 1
l
Hi! No you do not need server in this case --
flow.run
should start the flow run instantly — if there is a schedule on the flow it will wait for the schedule, but otherwise execution should start immediately in-process. Is there any output at all or does it immediately hang?
b
Hi Laura, thanks for the reply, doh, just realised there's a schedule on the task -- how do you go about testing scheduled tasks?
Ah, just did
flow.schedule = None
and that worked also
l
Awesome yeah, for quick testing of a scheduled flow in general you’ll want to take the schedule off (or if you are in an automated testing framework and really want to test the schedule, mock the time)
b
nice, thanks for the help. I'll look for an example in the prefect tests themselves.
l
Great! Doing a super quick perusal myself, it looks like we mostly unittest the internals of schedules more than mock time at all, but as a personal recommendation if you wanted to automate an end-to-end test for a flow with a schedule on it yourself including testing that it trips at the time you expect, you might use something like
freezegun
if you haven’t before (https://pypi.org/project/freezegun/)
j
TIL freezegun
b
I was like wowzer freezegun seems rad, can't wait to tell the team about it. Go to pip install it to try it out... already installed haha
😂 1