本文共 1277 字,大约阅读时间需要 4 分钟。
assertEqual 如果两个值相等,则pass
assertNotEqual 如果两个值不相等,则passassertTrue 判断bool值为True,则passassertFalse 判断bool值为False,则passassertIsNone 不存在,则passassertIsNotNone 存在,则passdef fibo(x): if x == 0: resp = 0 elif x == 1: resp = 1 else: return fibo(x-1) + fibo(x-2) return respassert fibo(5) == 5
assertAlmostEqual(a, b) round(a-b, 7) == 0
assertNotAlmostEqual(a, b) round(a-b, 7) != 0 assertGreater(a, b) a > b 2.7assertGreaterEqual(a, b) a >= b 2.7assertLess(a, b) a < b 2.7assertLessEqual(a, b) a <= b 2.7assertRegexpMatches(s, re) regex.search(s) 2.7assertNotRegexpMatches(s, re) not regex.search(s) 2.7assertItemsEqual(a, b) sorted(a) == sorted(b) and works with unhashable objs 2.7assertDictContainsSubset(a, b) all the key/value pairs in a exist in b 2.7assertMultiLineEqual(a, b) strings 2.7assertSequenceEqual(a, b) sequences 2.7assertListEqual(a, b) lists 2.7assertTupleEqual(a, b) tuples 2.7assertSetEqual(a, b) sets or frozensets 2.7assertDictEqual(a, b) dicts 2.7assertMultiLineEqual(a, b) strings 2.7assertSequenceEqual(a, b) sequences 2.7assertListEqual(a, b) lists 2.7assertTupleEqual(a, b) tuples 2.7assertSetEqual(a, b) sets or frozensets 2.7assertDictEqual(a, b) dicts 2.7转载于:https://blog.51cto.com/13914991/2175481