为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Cats萌萌 2022-06-14 16:43:20
我有一个元组:expected = (list, string)第一个参数是一个列表,第二个是字符串。列表项可以有任何顺序。通常在声明一个列表时,我会assertCountEqual()检查项目而不考虑或顺序。如何对包含列表的元组进行单元测试?
查看完整描述

1 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

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


查看完整回答
反对 回复 2022-06-14
  • 1 回答
  • 0 关注
  • 82 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信