Skip to content

omnipy.components.prefect.lazy_import

FUNCTION DESCRIPTION
set_prefect_config_path
use_ephemeral_mode_for_tests

Force Prefect into ephemeral local mode when running under pytest.

set_prefect_config_path

set_prefect_config_path()
Source code in src/omnipy/components/prefect/lazy_import.py
def set_prefect_config_path():
    prefect_module_dir = Path(__file__).resolve().parent

    os.environ['PREFECT_LOGGING_SETTINGS_PATH'] = \
        f"{prefect_module_dir.joinpath('settings', 'logging.yml')}"

use_ephemeral_mode_for_tests

use_ephemeral_mode_for_tests()

Force Prefect into ephemeral local mode when running under pytest.

The test suite should not depend on external Prefect Cloud or server settings, so this helper clears remote-API settings and enables ephemeral mode when pytest has been imported.

Source code in src/omnipy/components/prefect/lazy_import.py
def use_ephemeral_mode_for_tests():
    """Force Prefect into ephemeral local mode when running under ``pytest``.

    The test suite should not depend on external Prefect Cloud or server settings, so
    this helper clears remote-API settings and enables ephemeral mode when ``pytest``
    has been imported.
    """
    if 'pytest' in sys.modules:
        os.environ['PREFECT_SERVER_ALLOW_EPHEMERAL_MODE'] = 'True'
        os.environ['PREFECT_API_KEY'] = ''
        os.environ['PREFECT_API_URL'] = ''