def get_temp_filename(cls, file_name):
"""Get a unique filepath name in the testing directory.
The file will not be created, that is up to the caller. This file will be deleted when
the tests are finished.
@param file_name: A partial path ex: 'directory/somefile.txt'
@return The full path to the temporary file.
"""
temp_dir = Settings.temp_dir
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
base_name, ext = os.path.splitext(file_name)
path = '{0}/{1}{2}'.format(temp_dir, base_name, ext)
count = 0
while os.path.exists(path):
# If the file already exists, add an incrememted number
count += 1
path = '{0}/{1}{2}{3}'.format(temp_dir, base_name, count, ext)
cls.files_created.append(path)
return path
评论列表
文章目录