Patricio Navarro
08/02/2024, 1:45 PMMarvin
08/02/2024, 1:46 PM.fn()
in Prefect, it accesses the original function directly, allowing you to test the task or flow in isolation without invoking the full Prefect runtime environment. This is particularly useful for unit testing.
Here’s an example of how to use .fn()
with a task:
python
from prefect import flow, task
@task
def my_favorite_task():
return 42
@flow
def my_favorite_flow():
val = my_favorite_task()
return val
def test_my_favorite_task():
assert my_favorite_task.fn() == 42
In this code:
- my_favorite_task.fn()
calls the original function defined in the @task
decorator, bypassing Prefect's orchestration mechanisms.
Source: https://docs.prefect.io/latest/guides/testing/