Jonathan
Jonathan

Reputation: 8901

Test: string is not string

This test result boggles my mind. What could be the fault of this? It is the exact same word after all.

======================================================================
FAIL: test_make_table_list_supplier_unknown (__main__.ConvertingListToDic)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_scraping.py", line 20, in test_make_table_list_supplier_unknown
    self.assertIs(no_supplier_table[0].get('ingredient list')[0]['ingredient'], 'Crystalline Silica')
AssertionError: 'Crystalline Silica' is not 'Crystalline Silica'

Upvotes: 1

Views: 188

Answers (2)

user2357112
user2357112

Reputation: 281594

is tests object identity. Distinct objects can be equal; what you want is assertEqual.

Upvotes: 2

Tim
Tim

Reputation: 43344

assertIs(a, b) checks if a and b are the same object.

You probably want to check for value only, in that case use assertEqual()

self.assertEqual(no_supplier_table[0].get('ingredient list')[0]['ingredient'], 'Crystalline Silica')

Note that there is also an assertEquals(), which is deprecated so be sure to use assertEqual()

See the python docs for more detailed information.

https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertIs

and

https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertEqual

Upvotes: 6

Related Questions