pytest断言

  • pytest中可以用python的assert断言,也可以写多个断言,但一个失败,后面的断言将不再执行
  • 安装pytest断言自带插件:pip3 install pytest-assume
  • 下面是实例对比:
    import pytest
    
    # python 自带断言,一旦失败后面代码不会执行
    def test_add1():
        assert 1 + 4 == 6
        assert 1 + 4 == 5
        print("测试完成")
    
    
    
    
    
    #pytest 自带断言,断言失败也会继续执行直到函数本身执行完毕,在有多个断言情况下更高效
    def test_add2():
        pytest.assume(1 + 4 == 5)
        pytest.assume(1 + 3 == 3)
        pytest.assume(2 + 5 == 7)
        pytest.assume(2 + 5 == 9)
        print("测试完成")
    View Code

     

posted @ 2022-04-07 09:44  localhost;  阅读(35)  评论(0编辑  收藏  举报