provides an environment for flows to be tested, how might I go about testing a task in Prefect 2.0? It seems like calling
.run()
on tasks has not made it over from 1.0 yet.
a
Anna Geller
05/05/2022, 4:11 PM
The easiest would be to look at the tests in the repo e.g. this one
In Prefect 2.0 you can call arbitrary Python code in your flows so testing anything in Prefect 2.0 is quite similar to writing tests for anything in Python. What in particular would you like to test?
Thanks Anna and Nate - ad-hoc flows for testing single classes will work, although it would be somewhat useful to be able to call tasks out of context.
π 1
n
Nate
05/05/2022, 6:02 PM
you can use the
.fn()
method on tasks like
Copy code
import pytest
from my_prefect_collection.tasks import my_task
async def test_successful_task(mock_successful_calls):
my_task_result = await my_task.fn()
assert type(trigger_sync_result) is whatever
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.