def create_tmp_test(code, prefix='tmp', delete=True, **kwargs):
 py = tempfile.NamedTemporaryFile(prefix=prefix, delete=delete)
 code = code.format(**kwargs)
 if IS_PY3:
  code = code.encode('UTF-8')
 py.write(code)
 py.flush()
 st = os.stat(py.name)
 os.chmod(py.name, (st.st_mode | stat.S_IEXEC))
 return py

def create_tmp_test ( code , prefix = 'tmp' , delete = True , ** kwargs ) : py = tempfile . NamedTemporaryFile ( prefix = prefix , delete = delete ) code = code . format ( ** kwargs ) if IS_PY3 : code = code . encode ( 'UTF-8' ) py . write ( code ) py . flush ( ) st = os . stat ( py . name ) os . chmod ( py . name , ( st . st_mode | stat . S_IEXEC ) ) return py
creates a temporary test file that lives on disk .