Python脚本解决一些繁琐的测试问题
用Python脚本:根据文件列表“stab_case.txt”上面的文件名称,删除指定文件夹(包括子文件夹)下面的文件。
#coding=utf-8
importos
WORKDIR=os.getcwd()#不必修改
#提供局排错误案例信息的报告全集,除非生成的报告名改变否则不必改动
g_ResultTxtName=['stab_case.txt',]
#如果把该程序拷到Cases\\Case下则不需要设置
#否则写成如这样的案例存放的绝对路径'E:\\render\\Cases\\Case'
CasePath=WORKDIR
defdeleteFile(filepath):
try:
ifnotos.path.exists(filepath):
printfilepath,"notexist!"
return0
ifnotos.path.isfile(filepath):
printfilepath,"isnotafile!"
return0
os.remove(filepath)
print"Delete",filepath,"succeded!"
return1
except:
print"Delete",filepath,"failed!"
pass
return0
defanalyseReport(txtPath):
pathList=[]
try:
report=open(txtPath,'r')
exceptException,ex:
printstr(Exception),':',str(ex)
report.close()
returnpathList
forlineinreport:
iflen(line)<=len('\n'):
continue
#line=line.decode('cp936')
pathList.append(line[:-1])#去掉开头的\t和最后的\n
report.close()
pathList.sort()
returnpathList
if'__main__'==__name__:
foriteming_ResultTxtName:
txtPath=os.path.join(WORKDIR,item)
pathList=[]
ifos.path.exists(txtPath):
pathList=analyseReport(txtPath)
forPathinpathList:
docPath=os.path.join(CasePath,Path)
deleteFile(docPath)
print'DeleteOver'
os.system("pause")
以上内容为大家介绍了Python脚本解决一些繁琐的测试问题,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。http://www.mobiletrain.org/

相关推荐HOT
更多>>
python怎么输入多变量
Python同时输入多个值 1.同时输入多个字符串,字符串间以逗号/空...详情>>
2023-11-12 23:43:43
python岗位主要做什么工作?
python的工作岗位还是很多的,涉及的工作方向也很广,下面举一些常见的岗位,大家可以参考:Web应用开发Python经常被用于Web开发。例如,通过mo...详情>>
2023-11-12 23:05:27
python能做网站吗?
python可以做网站,Python有很多优秀的网站框架,可以非常快速的建一个网站。比如django之类的框架。Django、TurboGears、Eurasia、UliWeb等:...详情>>
2023-11-12 21:47:07
python中的int是什么意思?
python中的int()函数用于将一个字符串或数字转换为整型。语法以下是int()方法的语法:classint(x,base=10)参数x--字符串或数字。base--进制数,...详情>>
2023-11-12 21:21:30