David Deepwell
03/25/2025, 10:22 PMMarvin
03/25/2025, 10:23 PMPREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW
environment variable to ignore
. This will prevent the warning from being logged when your logger attempts to send logs to the API without a flow run ID.
Here's how you can set this environment variable in your test environment:
bash
export PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW=ignore
Alternatively, you can set this environment variable within your Python code before the logger is used:
python
import os
os.environ["PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW"] = "ignore"
This configuration option controls the behavior when loggers attempt to send logs to the API handler from outside of a flow. The available options are warn
, error
, and ignore
, with the default being warn
.
For more information, you can refer to the Prefect settings documentation.
If you need to use a logger that doesn't send logs to the Prefect API, consider using get_logger()
from the prefect.logging
module.David Deepwell
03/25/2025, 10:25 PMMarvin
03/25/2025, 10:25 PMprefect.settings
module to configure the environment variable programmatically. This should ensure that the setting is applied correctly during the execution of your tests. Here's how you can do it:
python
from prefect.settings import temporary_settings
with temporary_settings(updates={"PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW": "ignore"}):
# Your test code here
The temporary_settings
context manager allows you to temporarily override Prefect settings, ensuring that the environment variable is set appropriately during the execution of the block. This should suppress the warning without affecting other parts of your application.
For more details on Prefect's logging and settings, you can explore the logging documentation and settings documentation.