Hi With Prefect 1 - Any tips for detecting if a ta...
# prefect-community
Hi With Prefect 1 - Any tips for detecting if a task was used within another task without using
? I want to add a pytest to check and prevent adding incorrect task uses like this.
Copy code
import prefect

def task1(par):
    task2()  # this is incorrect! it should be task2.run()

def task2():
    return 1

with prefect.Flow("Sample flow") as flow:
    aa = prefect.Parameter("aa")
doesn't return errors/warnings, since it doesn't check what's happening inside each task. Meanwhile, in the task, there's another task hiding and being used incorrectly. It will fail when running the flow.
Copy code
ValueError: Could not infer an active Flow context while creating edge to <Task: task2>. This often means you called a task outside a `with Flow(...)` block. If you're trying to run this task outside of a Flow context, you need to call `task2.run(...)`
I could do a
in my test, but that can be cumbersome and require a lot of scaffolding in terms of setting up mocks, and even with mocks, the flow run might just be too slow. A
can be handly, but I'm finding some difficulty in writing such a function.