hi all! Trying to test tasks that make use of the ...
# ask-community
a
hi all! Trying to test tasks that make use of the run context with
Prefect 1
I could do this:
Copy code
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
?
Untitled.py
d
I have issues with
get_run_context
being called from
task
.
I prefer explicitly using
from prefect.context import FlowRunContext
when extract flow run information.
a
@Deceivious have changed to
Copy code
from 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…