测试:字符串不是字符串

Jon*_*han 1 python unit-testing

这个测试结果令我难以置信.这可能是什么错?毕竟这是完全相同的词.

======================================================================
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'
Run Code Online (Sandbox Code Playgroud)

Tim*_*Tim 6

assertIs(a, b)检查ab是相同的对象.

您可能只想检查值,在这种情况下使用 assertEqual()

self.assertEqual(no_supplier_table[0].get('ingredient list')[0]['ingredient'], 'Crystalline Silica')
Run Code Online (Sandbox Code Playgroud)

请注意,还有一个assertEquals()已弃用,因此请务必使用assertEqual()

有关更多详细信息,请参阅python文档.

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

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