@contextlib.contextmanager<EOL>def _setenv(key, value):
old_value = os.environ.get(key, None)<EOL>if value is None:<EOL><INDENT>os.environ.pop(key, None)<EOL><DEDENT>else:<EOL><INDENT>os.environ[key] = value<EOL><DEDENT>yield<EOL>if old_value is None:<EOL><INDENT>os.environ.pop(key, None)<EOL><DEDENT>else:<EOL><INDENT>os.environ[key] = value<EOL><DEDENT>
Context manager to set an environment variable temporarily.