Lana Dann

    Lana Dann

    4 months ago
    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?
    Kevin Kho

    Kevin Kho

    4 months ago
    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?
    Lana Dann

    Lana Dann

    4 months ago
    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?
    Kevin Kho

    Kevin Kho

    4 months ago
    That is a task so you can do
    abc.run()