Ben Muller
11/04/2022, 2:40 AMget_run_logger()
.
In order to test that function I am using .fn()
but I can not test it because get_run_logger()
failed every time because E prefect.exceptions.MissingContextError: There is no active flow or task run context.
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?Nate
11/04/2022, 3:19 AMfrom prefect.logging import disable_run_logger
def test_some_flow():
with disable_run_logger():
call_some_flow_that_uses_logger.fn()
Ben Muller
11/04/2022, 3:21 AMNate
11/04/2022, 3:24 AMyour_flow.fn()
within the disable_run_logger
context manager block in testsBen Muller
11/04/2022, 3:25 AMCole Murray
11/04/2022, 3:40 AM@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)
This makes it quite easy to test your code, as it lives outside of prefect context.Ben Muller
11/04/2022, 3:42 AM