vendredi 27 octobre 2017

How to compare lists in pytest using assert statement?

I am try to compare results of two lists using assert statement to test the function using pytest. Whenever I try to compare using assert statement, my expected result is automatically converted as string with double quotes. This is so far I have done:

# read data from xlsx file 

book = xlrd.open_workbook("nameEntityDataSet.xlsx")

first_sheet = book.sheet_by_index(0) # get first worksheet

# take second element(index starts from 0) from first row

se1 = first_sheet.row_values(1)[1]

print "se1 ", se1 #returns me list:
# take third element(index 2) from first row 

se2 = first_sheet.row_values(1)[2]

expected_output = first_sheet.row_values(1)[3]

#expected output is printed as:  [['UAE', 'United'], ['UAE', 'Arab'], ['UAE', 'Emirates']]

current_output = [['UAE', 'United'], ['UAE', 'Arab'], ['UAE', 'Emirates']]

#When I do assert to compare both outputs
assert current_output == expected_output

#I get error: 

E    assert [['UAE', 'United'], ['UAE', 'Arab'], ['UAE', 'Emirates']] == "[['UAE', 'United'], ['UAE', 'Arab'], ['UAE', 'Emirates']]"
test_wordAligner.py:15: AssertionError

I do not know, why it adds double quotation marks with expected output, due to this reason I am getting AssertionError.I have searched a lot but did not find any helpful answer in my case. Please note that I want solution in pytest not unittest

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire