assert

断言方法

以下为unittest框架的TestCase类提供的方法
方法检查版本Note
assertEqual(a,b)a == b
assertNotEqual(a,b)a != b
assertTrue(x)bool(x) is True表达式(bool(x))是是否等于True/False
assertFalse(x)bool(x) is False
assertIs(a,b)a is b3.1a和b是否为同一对象
assertIsNot(a,b)a is not b3.1
assertIsNone(x)x is None3.1表达式是否为None对象
assertIsNotNone(x)x is not None3.1
assertIn(a,b)a in b3.1a是否在b中,b是否包含a
assertNotIn(a,b)a not in b3.1
assertIsInstance(a.b)isinstance(a,b)3.2a是否为b的一个实例
assertNotIsInstancenot isinstance(a,b)3.2