Ben Muller11/04/2022, 2:40 AM
. In order to test that function I am using
but I can not test it because
failed every time because
Besides possibly using an optional kwarg in every single task that I have, how can I get around this to test my tasks logic properly?
E prefect.exceptions.MissingContextError: There is no active flow or task run context.
Nate11/04/2022, 3:19 AM
from prefect.logging import disable_run_logger def test_some_flow(): with disable_run_logger(): call_some_flow_that_uses_logger.fn()
Ben Muller11/04/2022, 3:21 AM
Nate11/04/2022, 3:24 AM
context manager block in tests
Ben Muller11/04/2022, 3:25 AM
Cole Murray11/04/2022, 3:40 AM
This makes it quite easy to test your code, as it lives outside of prefect context.
@task def some_task_here(something: str): some_task = SomeTask() # can move outside of this function to avoid instantiation each time if desired some_task.run(something)
Ben Muller11/04/2022, 3:42 AM