https://prefect.io logo
Title
l

Lana Dann

05/04/2022, 7:23 PM
what’s the best way to call a task within a prefect flow (for integration tests)?
flow.<method name>(<method arguments>)
doesn’t work, so i assume we’d need to grab the task from
flow.tasks
and then run the task object. so my follow up question would be, what is the best way to retrieve a task by name from a
Flow
object?
k

Kevin Kho

05/04/2022, 7:50 PM
Let me try it out
Have you seen this page though?
Like this maybe?
from prefect import Flow, task

@task
def abc(x):
    return x

@task
def bcd(x):
    return x

with Flow("..") as flow:
    a = abc(1)
    b = bcd(1)

print(flow.tasks)
print(list(flow.tasks)[0].name)
And then find the one with the name you want? But I think you can just test the task directly?
l

Lana Dann

05/04/2022, 8:02 PM
hmm, i know the name of the task i want to test but i don’t know how to test running that task specifically. i guess i can just import the task directly and run it? if you have
@task
def abc(x):
    return x
and you import
from myflow import abc
then is that a task object or just a method?
k

Kevin Kho

05/04/2022, 8:23 PM
That is a task so you can do
abc.run()
🙌 2