@contextlib.contextmanager
def _setenv(key, value):
 old_value = os.environ.get(key, None)
 if (value is None):
  os.environ.pop(key, None)
 else:
  os.environ[key] = value
 (yield)
 if (old_value is None):
  os.environ.pop(key, None)
 else:
  os.environ[key] = value

@ contextlib . contextmanager def _setenv ( key , value ) : old_value = os . environ . get ( key , None ) if ( value is None ) : os . environ . pop ( key , None ) else : os . environ [ key ] = value ( yield ) if ( old_value is None ) : os . environ . pop ( key , None ) else : os . environ [ key ] = value
context manager temporarily overriding env with given key/value pairs .