如何对包含列表的元组进行unittest(断言)?

2024-03-28 13:11:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个元组:

expected = (list, string)

第一个参数是列表,第二个参数是字符串。你知道吗

列表项可以有任何顺序。通常在断言一个列表时,我会执行assertCountEqual(),检查项目的顺序。如何对包含列表的元组进行单元测试?你知道吗


Tags: 项目字符串列表参数string顺序断言单元测试
1条回答
网友
1楼 · 发布于 2024-03-28 13:11:09
def assertMyTupleEqual(self, expected, actual):
    self.assertEqual(type(expected), type(actual))  # check they are the same type
    self.assertEqual(len(expected), len(actual))  # check they are the same length
    self.assertEqual(expected[1], actual[1])  # check they have the same string
    self.assertCountEqual(expected[0], actual[0])  # check they have the same list    

相关问题 更多 >