logFields = []
testResultList = self.fields["testResult"]
for i in range(len(testResultList)):
if testResultList[i]["status"] == u"成功":
logFields.append(self.fields["testResult"][i]["log"][:-1])
if testResultList[i]["status"] == u"失败":
logFields.append(self.fields["testResult"][i]["log"])
newFields = []
for number in range(len(logFields)):
logJoin = "".join(logFields[number])
if "Traceback" not in logJoin:
newFields.append(logFields[number])
else:
add = logFields[number][0].split("\n")[:-1]
newFields.append(add)
finalFields = []
for num in range(len(newFields)):
if num == 0:
finalFields.append(newFields[num])
else:
length = len(newFields[num]) - len(newFields[num - 1])
d = copy.deepcopy(newFields[num])
new = []
for m in range(length):
get = d.pop()
new.insert(0, get)
finalFields.append(new)
# print("logFields",logFields)
# print("newFields",newFields)
# print("finalFields",finalFields)
for number in range(len(finalFields)):
if self.fields["testResult"][number]["status"] == u"成功":
self.fields["testResult"][number]["log"] = finalFields[number] + [""]
else:
self.fields["testResult"][number]["log"] = finalFields[number] + logFields[number][1:] + [""]
# print(fields)
或者