When testing Prefect flows we can use the harness ...
# ask-community
m
When testing Prefect flows we can use the harness utility function and a fixture to ensure an SQLite database is used. This has a startup cost, and we have the overhead of actually executing our flows as a series of tasks and functions. However, we can also run
.fn
on a flow to run it directly. Unfortunately, this results in an error if the flow calls tasks that aren't also ran using
.fn
. Is there a way to run a flow such that both the flow itself and all tasks are automatically called as
task.fn
and
flow.fn
? This would be really useful for lightweight E2E tests that don't need the resilience of actually running the flows, checking states etc.
Seems like this one: https://github.com/PrefectHQ/prefect/pull/11136 would be very relevant in achieving this, but it was closed without any comment about why. @Nate, has this feature been abandoned?
n
hi @Morten Hauge - that was an exploratory PR to investigate the client-side engine changes required to run tasks outside of a flow. One would still have to use something like the test harness after that change, since all the db reads/writes that occur when orchestrating a task would still happen, it would just happen without a parent flow run this would not be byproduct of that PR
such that both the flow itself and all tasks are automatically called as
task.fn
and
flow.fn
what troubles are you running into as it relates to the overhead of
prefect_test_harness
?
m
Sorry about the super long delay @Nate, got majorly side-tracked for a while so didn't have time to get back to this before now. The main issue I have with the harness is that it treats my flows as flows, which is much slower than just running with
.fn
. However, since using
.fn
on the flow doesn't propagate down to the task-level, that doesn't work by itself. I also can't find any documentation or clean way to disable retries for all of my tasks and flows inside my tests, which means that tasks that are expected to fail in my test take forever to run, since it has to run through all of the retries first.