John O'Farrell
11/15/2023, 2:41 PMTaylor Curran
11/15/2023, 5:48 PMKevin Grismore
11/15/2023, 5:58 PMmy_task.fn()
?Taylor Curran
11/15/2023, 5:59 PM@flow
def my_flow():
print('hi')
# to run
my_flow()
John O'Farrell
11/15/2023, 6:04 PMmy_task.fn()
for flows. I'm trying to import the flow into a unit test file and when I call it without a decorator in the test module it still acts like a prefect flowKevin Grismore
11/15/2023, 6:06 PM.fn()
as well, but that doesn't propagate down to the task level. For example:
from prefect import flow, task
@flow(log_prints=True)
def my_flow():
say_hello()
@task
def say_hello():
print(f"Hello!")
if __name__ == "__main__":
my_flow.fn()
will land you in RuntimeError
territory because tasks cannot be run outside of a flowJohn O'Farrell
11/15/2023, 6:07 PMKevin Grismore
11/15/2023, 6:07 PMJohn O'Farrell
11/15/2023, 6:15 PMKevin Grismore
11/15/2023, 6:17 PMJohn O'Farrell
11/15/2023, 6:30 PMflow.fn()
didn't allow the tasks within flows to be run as regular code because that would have been pretty much exactly what I'm looking forKevin Grismore
11/15/2023, 7:27 PMJohn O'Farrell
11/15/2023, 7:39 PMKevin Grismore
11/15/2023, 7:39 PMKevin Grismore
11/15/2023, 7:43 PMMorten Hauge
01/15/2024, 8:49 AMMorten Hauge
01/15/2024, 9:55 AMmy_flow.fn()
here everything is ran as normal python functions, without involving Prefect at all. This means that run_logger, retries etc. can all be circumvented and ignored where that makes sense. I'm using pytest here, but you should be able to achieve the same thing using just the unittest library.