I have a requirement to drop my test results into a csv for reporting. In my python test code when I don’t have a value, my variables are filled in the python way with None.
I have been asked to replace these with “Null” in the CSV for the reporting tool. I am thinking this is easy and has probably be solved a hundred times.
Here is the code I came up with:
for field in (TestCase.productUnderTest,TestCase.versionUnderTest,TestCase.name,TestCase.results,TestCase.lastTestEnd,TestCase.parent,TestCase.level):
if field == None:
field = 'Null'
ME.csvoutput.write("%s,%s,%s,%s,%s,%s,%s\n" % (TestCase.productUnderTest,TestCase.versionUnderTest,TestCase.name,TestCase.results,TestCase.lastTestEnd,TestCase.parent,TestCase.level))
Unfortunately that only changes the field within the scope of the for loop. How can I change it for the scope of the write statement.
(I would be quite happy to just write “Null” and leave my variables unchanged, but I can work either way.)
1 Answer