I am trying to send the failed values to a CSV file but it's only giving me the last failed value in the list.
print(("Folder\t"+ "Expected\t"+ "Actual\t"+"Result").expandtabs(20))
for key in expected:
expectedCount = str(expected[key])
actualCount = "0"
if key in newDictionary:
actualCount = str(newDictionary[key])
elif expectedCount == actualCount:
result = "Pass"
else:
result = "Fail"
with open('XML Output.csv', 'w',encoding='utf-8', newline="") as csvfile:
header = ['Folder', 'Expected', 'Actual','Result']
my_writer = csv.writer(csvfile)
my_writer.writerow(header)
my_writer.writerow([key, expectedCount, actualCount, result])
csvfile.close()
print((key + "\t"+expectedCount+ "\t"+actualCount+ "\t"+result).expandtabs(20))
print("======================== Data Exported to CSV file ========================")
Output:
Folder Expected Actual Result
D 2 1 Fail
Here is what the output should be:
Folder Expected Actual Result
A 2 1 Fail
B 2 1 Fail
C 2 1 Fail
D 2 1 Fail
'w'when you open your file instead of'a'to append the data