zoukankan      html  css  js  c++  java
  • 【unittest】unittest单元模块做assert

    我在Windows上开发Python用的版本是2.7,在Ubuntu上开发的版本是2.6,而在Python的unittest模块中,有几个方法是在2.7才有的,它们是:

    MethodChecks thatNew in
    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 isb 2.7
    assertIsNot(a,b) a isnotb 2.7
    assertIsNone(x) x isNone 2.7
    assertIsNotNone(x) x isnotNone 2.7
    assertIn(a,b) a inb 2.7
    assertNotIn(a,b) a notinb 2.7
    assertIsInstance(a,b) isinstance(a, b) 2.7
    assertNotIsInstance(a,b) not isinstance(a,b) 2.7

    其他assert

    Method     Checks that     New in
    assertAlmostEqual(a, b)     round(a-b, 7) == 0      
    assertNotAlmostEqual(a, b)     round(a-b, 7) != 0      
    assertGreater(a, b)     a > b     2.7
    assertGreaterEqual(a, b)     a >= b     2.7
    assertLess(a, b)     a < b     2.7
    assertLessEqual(a, b)     a <= b     2.7
    assertRegexpMatches(s, re)     regex.search(s)     2.7
    assertNotRegexpMatches(s, re)     not regex.search(s)     2.7
    assertItemsEqual(a, b)     sorted(a) == sorted(b) and works with unhashable objs     2.7
    assertDictContainsSubset(a, b)     all the key/value pairs in a exist in b     2.7
    assertMultiLineEqual(a, b)     strings     2.7
    assertSequenceEqual(a, b)     sequences     2.7
    assertListEqual(a, b)     lists     2.7
    assertTupleEqual(a, b)     tuples     2.7
    assertSetEqual(a, b)     sets or frozensets     2.7
    assertDictEqual(a, b)     dicts     2.7
    assertMultiLineEqual(a, b)     strings     2.7
    assertSequenceEqual(a, b)     sequences     2.7
    assertListEqual(a, b)     lists     2.7
    assertTupleEqual(a, b)     tuples     2.7
    assertSetEqual(a, b)     sets or frozensets     2.7
    assertDictEqual(a, b)     dicts     2.7

  • 相关阅读:
    ureport2 学习
    odoo 对接ureport2
    云服务器挂载新的硬盘
    linux ubuntu搭建文件共享服务nfs
    大厂MongoDB面试题集锦 转发:https://mp.weixin.qq.com/s/ImOgbKY5lSyMzmicu8xbXA
    写Python爬虫遇到的一些坑 转载:https://mp.weixin.qq.com/s/kfxJ7EKFeunGcjvBr0l7ww
    Selenium 爬取淘宝商品 转载:https://mp.weixin.qq.com/s/7aul82HqxszH5jH9pSpZrA
    tst
    Istio
    2021牛客暑期多校训练营7 F-xay loves trees
  • 原文地址:https://www.cnblogs.com/paulwinflo/p/4742834.html
Copyright © 2011-2022 走看看