@contextmanager
def __environ(values, remove=[]):
 new_keys = (set(environ.keys()) - set(values.keys()))
 old_environ = environ.copy()
 try:
  environ.update(values)
  for to_remove in remove:
   try:
    del environ[remove]
   except KeyError:
    pass
  (yield)
 finally:
  environ.update(old_environ)
  for key in new_keys:
   del environ[key]

@ contextmanager def __environ ( values , remove = [ ] ) : new_keys = ( set ( environ . keys ( ) ) - set ( values . keys ( ) ) ) old_environ = environ . copy ( ) try : environ . update ( values ) for to_remove in remove : try : del environ [ remove ] except KeyError : pass ( yield ) finally : environ . update ( old_environ ) for key in new_keys : del environ [ key ]
modify the environment for a test .