def environment_variable(key, value):
    """ Temporarily overrides an environment variable. """

    if key not in os.environ:
        previous = None
    else:
        previous = os.environ[key]

    os.environ[key] = value

    yield

    if previous is None:
        del os.environ[key]
    else:
        os.environ[key] = previous
def environment_variable ( key , value ) : if key not in os . environ : previous = None else : previous = os . environ [ key ] os . environ [ key ] = value yield if previous is None : del os . environ [ key ] else : os . environ [ key ] = previous
Temporarily overrides an environment variable.