import tempfile


def CreateTemporaryFile(**kwargs):
  """Gets an unopened temporary file.

  This is similar to UnopenedTemporaryFile except that CreateTemporaryFile is
  not a context manager and will not try to delete the allocated file, making it
  more convenient for unittest style programs to get temporary files in setUp
  and delete on tearDown.

  In comparison to tempfile.mkstemp, this function does not return an opened fd,
  thus avoiding potential file handle leaks.

  Args:
    Any allowable arguments to tempfile.NamedTemporaryFile (e.g., prefix,
      suffix, dir) except 'delete'.

  Returns:
    A file path.
  """
  assert kwargs.get('delete') is not True, 'CreateTemporaryFile never deletes.'
  kwargs['delete'] = False
  with tempfile.NamedTemporaryFile(**kwargs) as f:
    path = f.name
  return path