<@ULVA73B9P> what does prefect when a task or a fl...
# ask-marvin
p
@Marvin what does prefect when a task or a flow is called with ".fn()"?
m
When a task or a flow is called with
.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:
Copy code
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/
😲 1