简体   繁体   English

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

[英]How to unittest (assert) tuple containing list?

I have a tuple:我有一个元组:

expected = (list, string)

The first argument is a list and the second is string.第一个参数是一个列表,第二个是字符串。

The list items can have any order.列表项可以有任何顺序。 Usually when asserting a list I would do assertCountEqual() which checks the items irrespective or order.通常在断言一个列表时,我会执行assertCountEqual()来检查项目,而不考虑或顺序。 How to unit test tuple containing list?如何对包含列表的元组进行单元测试?

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    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM