def with_tempdir(callable):
 if isgeneratorfunction(callable):
  def proxy(*args, **kwargs):
   old_tmpdir = tempfile.gettempdir()
   new_tmpdir = tempfile.mkdtemp(prefix='temp-lgc-')
   tempfile.tempdir = new_tmpdir
   try:
    for x in callable(*args, **kwargs):
     (yield x)
   finally:
    try:
     rmtree(new_tmpdir, ignore_errors=True)
    finally:
     tempfile.tempdir = old_tmpdir
  return proxy
 @wraps(callable)
 def proxy(*args, **kargs):
  old_tmpdir = tempfile.gettempdir()
  new_tmpdir = tempfile.mkdtemp(prefix='temp-lgc-')
  tempfile.tempdir = new_tmpdir
  try:
   return callable(*args, **kargs)
  finally:
   try:
    rmtree(new_tmpdir, ignore_errors=True)
   finally:
    tempfile.tempdir = old_tmpdir
 return proxy

def with_tempdir ( callable ) : if isgeneratorfunction ( callable ) : def proxy ( * args , ** kwargs ) : old_tmpdir = tempfile . gettempdir ( ) new_tmpdir = tempfile . mkdtemp ( prefix = 'temp-lgc-' ) tempfile . tempdir = new_tmpdir try : for x in callable ( * args , ** kwargs ) : ( yield x ) finally : try : rmtree ( new_tmpdir , ignore_errors = True ) finally : tempfile . tempdir = old_tmpdir return proxy @ wraps ( callable ) def proxy ( * args , ** kargs ) : old_tmpdir = tempfile . gettempdir ( ) new_tmpdir = tempfile . mkdtemp ( prefix = 'temp-lgc-' ) tempfile . tempdir = new_tmpdir try : return callable ( * args , ** kargs ) finally : try : rmtree ( new_tmpdir , ignore_errors = True ) finally : tempfile . tempdir = old_tmpdir return proxy
decorator to give a single test a tempdir as argument to test method .