def _check_env_var ( envvar : str ) -> bool : if os . getenv ( envvar ) is None : raise KeyError ( "Required ENVVAR: {0} is not set" . format ( envvar ) ) if not os . getenv ( envvar ) : # test if env var is empty raise KeyError ( "Required ENVVAR: {0} is empty" . format ( envvar ) ) return True
python test if environment var is undefined or empty
Check Environment Variable to verify that it is set and not empty .
def _check_env_var(envvar: str) -> bool:
    """Check Environment Variable to verify that it is set and not empty.

    :param envvar: Environment Variable to Check.

    :returns: True if Environment Variable is set and not empty.

    :raises: KeyError if Environment Variable is not set or is empty.

    .. versionadded:: 0.0.12
    """
    if os.getenv(envvar) is None:
        raise KeyError(
            "Required ENVVAR: {0} is not set".format(envvar))
    if not os.getenv(envvar):  # test if env var is empty
        raise KeyError(
            "Required ENVVAR: {0} is empty".format(envvar))
    return True