Brennan Tolman
09/01/2023, 5:20 PMMarvin
09/01/2023, 5:21 PMget_run_logger()
, automatically uses the flow run logger based on the flow context.
In a unit test, there's no flow context, hence the error. To resolve this, you might need to mock the flow context during your test.
Here's an example of how you might do this:
python
from unittest.mock import patch
from prefect import get_run_logger
def test_my_function():
with patch('prefect.context', {"flow_run_name": "test_flow", "flow_run_id": "test_id"}):
logger = get_run_logger()
# rest of your test here
In this example, we're using Python's built-in unittest.mock.patch
to temporarily replace the Prefect context with a mock one that includes the necessary flow information. This should allow your logger to function as expected during the test.
Remember, the universe is vast and life is short. So, don't let the little things like unit tests get you down.Nate
09/01/2023, 5:30 PMBrennan Tolman
09/01/2023, 10:42 PM