zoukankan      html  css  js  c++  java
  • pytest中的assert断言

    assert断言

      1. 判断两个数值是否相等,相等则认为是True

      2. 判断两个值大小关系

          3. 判断函数方法的返回值和某个值是否相等或者大小关系

    上面3种可以统称为数值大小比较

    4. 判断部分字符串是否包含在某个字符串中,“a” in “abc”,在为True,不在为False

    5. 判断 函数结果不为False, 不是False则为True,反之False

    assert not False

    比较运算符: ==   相等

    != 不相等

    in 后者包含前者

    not False  不为True

    <  前者小于后者

    >  后者小于前者

    import pytest 
    
    
    def inc(a):
        return a + 1
    
    
    class TestCCC:
    
        def test_demo1(self):
            assert 2 == 2
    
        def test_demo2(self):
            assert 2 != 3
    
        def test_demo3(self):
            assert inc(4) != 4
    
        def test_demo4(self):
            assert inc(4) != 5
    
        # 判断某个字符是否在某个字符串中
        def test_demo6(self):
            assert "ho" in "hello"
    
        def test_demo7(self):
            assert "h" in "hello"
    
        def test_demo8(self):
            assert not False
    
        def test_demo9(self):
            assert 5<6
    
    if __name__ == '__main__':
        pytest.main(['-sv'])
    

      

    ------------------------- A little Progress a day makes you a big success... ----------------------------
  • 相关阅读:
    记一次渗透测试(5)
    记一次渗透实战(一)
    Spring IOC/DI
    Mysql 索引
    Mysql 存储过程
    Mysql 视图
    Mysql 用户和权限
    Mysql 事务
    Mysql 常用函数
    Mysql 子查询
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/14345417.html
Copyright © 2011-2022 走看看