https://prefect.io logo
Title
m

Matt Fysh

09/02/2022, 11:42 PM
Hi all, is there a way to disable flow/task decorators for testing?
1
a

Anna Geller

09/03/2022, 1:16 PM
In 2.3 we added a utility disable_run_logger that allows you to disable Prefect logger for testing - other than logger, you can test your tasks and flows the same way as any Python functions
k

kwmiebach

09/03/2022, 2:42 PM
@Matt Fysh Yes that would help a lot. I find myself going through different files and commenting decorators and other prefect stuff, just to be able to run the 'naked' version, and then putting it all back. Maybe some environment variable that magically turns off all prefect stuff would work. It is very nice, how easy it is, to take an existing codebase, sprinkle some decorators on it and have prefect working. But very soon prefect is baked in. To find out how the code works without prefect can be very helpful in debugging, for example with async or threading stuff.
a

Anna Geller

09/03/2022, 5:39 PM
You can totally do that, you can run any underlying bare function e.g. using task.fn()
m

Matt Fysh

09/03/2022, 8:02 PM
Is there a global setting though? It would be nice if
flow
and
task
could be configured at a global level to essentially be no-ops, without having a to change the calling sites (by adding
.fn()
then removing it again later)
testing is one reason, another is faster iteration cycles when developing complex DAGs locally
a

Anna Geller

09/04/2022, 7:45 AM
There is no DAG in Prefect 2, you can run all flows and tasks as in any Python. If your concern is that local execution is tracked in the Prefect backend, you can switch to a testing profile and run it with a local throwaway DB Iterative local development is something Prefect 2 was built for in a way you can use tasks in flows as any normal Python code. I would encourage you to try iteratively build with decorators directly