import os
import time
# 获取当前系统时间
curTime = time.strftime("%Y-%m-%d_%H%M", time.localtime())
# 以当前系统时间生成log文件
# open("{}.log".format(curTime),"a", encoding="utf-8")
# os.system("cd. > {}.log".format(curTime))
# 获取当前文件夹路径
base_path = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
file_path= "D:\脚本文件\KM、ORDM回归UI自动化脚本\KM\在线\答案配置\答案编辑"
sum = 0
for file_name in os.listdir(file_path):
if file_name.find(".air")>0:
sum=sum+1
print("当前执行第 {} 个案例, 名称为:{}".format(sum, file_name))
f = open("{}.log".format(curTime),"a+", encoding="utf-8")
f.write("当前执行第 {} 个案例, 名称为:{}".format(sum, file_name))
f.write("\n")
f.write("--"*20)
f.write("\n")
f.close()
cmd = "airtest run {} >> {}.log".format(file_path+"\\"+file_name, curTime)
print("值‘{}’".format(cmd))
# exe_com = os.system(cmd)
os.system(cmd) # 执行脚本
time.sleep(3)
f = open("{}.log".format(curTime),"a+", encoding="utf-8")
f.write("共识别 {} 个脚本".format(sum))
f.close()
Traceback (most recent call last):
File "C:\Users\v_tongtongyou\PycharmProjects\KnowledgeBaseUiTest\Common\demo.py", line 19, in <module>
f = open("{}.log".format(curTime),"a+", encoding="utf-8")
PermissionError: [Errno 13] Permission denied: '2023-07-19_1446.log'