https://prefect.io logo
Title
j

jcozar

04/07/2023, 5:54 PM
Hi! In prefect 1.0 I used
with prefect.context({"date": datetime.datetime(2011, 1, 1)}):
to set context variables and test my flows. Is there something similar in prefect 2.0 to set the
start_date
variable from the flow run context (
prefect.context.get_run_context()
)? Thank you!
āœ… 1
c

Chris White

04/07/2023, 6:14 PM
Hi! Yes there is, we call it `prefect.runtime`; you can read up on it here: https://docs.prefect.io/latest/concepts/runtime-context/ And see the current list of supported values within the API reference; for
start_date
I think you'll want
prefect.runtime.flow_run.scheduled_start_time
(ref: https://docs.prefect.io/latest/api-ref/prefect/runtime/flow_run/)
j

jcozar

04/07/2023, 7:30 PM
Thank you @Chris White! I'm reading about it, I think the documentation is clear. However, I don't see how to set a fixed value for scheduled_start_time. My use case is the following: ā€¢ I want to implement a flow whose execution depends on the current scheduled date. I get that value from
prefect.context.get_run_context().start_date
ā€¢ For testing purposes, I want to run my flow but setting the start_date to, for example, 2011-01-01. In prefect 1.0 there was a context that allowed to set the context variables to specific values just for testing purposes. Sorry if I missed it from the documentation, but I don't see it! Thank you again!
c

Chris White

04/07/2023, 7:41 PM
Oh I see - we don't currently expose a way to mock values for
runtime
but I think it's a good enhancement request - would you mind opening an issue for it?
@jcozar I've opened a PR to allow for this here: https://github.com/PrefectHQ/prefect/pull/9156
j

jcozar

04/07/2023, 8:37 PM
That's awesome! Thank you vey much šŸ‘
šŸ™Œ 1