def patch_environ(case, key, value):
 old_environ = os.environ.copy()
 def cleanup():
  os.environ.clear()
  os.environ.update(old_environ)
 os.environ[key] = value
 case.addCleanup(cleanup)

def patch_environ ( case , key , value ) : old_environ = os . environ . copy ( ) def cleanup ( ) : os . environ . clear ( ) os . environ . update ( old_environ ) os . environ [ key ] = value case . addCleanup ( cleanup )
add an environment variable for the duration of a test .