Andreas Tsangarides
05/25/2023, 9:20 AMPrefect 1 I could do this:
def test_my_task():
with prefect.context(dict(flow_run_id="test_id")):
my_task()
# assertions
how c an this be done in Prefect 2?Andreas Tsangarides
05/25/2023, 9:21 AMDeceivious
05/25/2023, 9:27 AMget_run_context being called from task .Deceivious
05/25/2023, 9:28 AMfrom prefect.context import FlowRunContext when extract flow run information.Andreas Tsangarides
05/25/2023, 10:16 AMfrom prefect import runtime
# inside flow
flow_run_id = runtime.flow_run.id
i.e. use the context inside the flows and pass extracted variables to tasks
this way the tasks can be tested independently (unit testing fashion)
was looking for a neat way to test the task itself…