unittest断言简介
unittest提供了丰富断言方法,包含数据类型num,字符串的比较,也包含实例的比较和空的比较
方法 | 检查 |
assertEqual(a, b) | a ==b |
assertNotEqual(a, b) | a !=b |
assertTrue(x) | bool(x) is True |
assertFalse(x) | Bool(x) is False |
assertIs(a, b) | a is b |
assertIsNot(a, b) | a is not b |
assertIsNone(x) | x is None |
assertIsNotNone(x) | x is not None |
assertIn(a, b) | a in b |
assertNotIn(a, b) | a not in b |
assertIsInstance(a, b) | isinstance(a,b) |
assertNotIsInstance(a, b) | not isinstance(a,b) |
unittest断言因为重复率高,所以亦可以对其进行封装,这样的封装很简单
原文:https://www.cnblogs.com/seyOrd/p/12680763.html