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