Hello everyone, I want to do a data check that is in csv and variable. I use unittest for this. The verification works, but there is a problem that if the data does not match, I cannot know where the problem is, namely in csv or in a variable. How can I get information in which place there is an error?

tb_row = [u'120 dev 15.61', u'126 kor 12.96', u'128 itsw 20.58'] for i, x in enumerate(tb_row): tb_row[i] = x rows = [] with open('/home/max/Desktop/test.csv', 'rb', ) as csvfile: the_file = csv.reader(csvfile, delimiter=',') for row in the_file: rows.extend([x.decode('utf8') for x in row]) q = u' '.join(tb_row).split() w = u' '.join(rows).split() for index, value in enumerate(q): # comparing csv with web self.assertEqual(w[index], value) 

    1 answer 1

    If I understand you correctly, you want to check the input data from csv with the data that you already have in the logic of your program. That is, verification is a part of program logic. If so, you don't need unittest here. unittest - module for creating unit tests. Of course, you can try to stuff it into the logic of the application, but in my opinion you should not do this.

    If the data does not match, and it is unclear where the correct data is contained (either in csv or in your program), no one will tell you what is right and what is not. Therefore, I propose to do as follows

     for index, value in enumerate(q): # comparing csv with web if w[index] != value: raise Exception("data not equal, index: %s, %s != %s" % (index, w[index], value))