pytest学习3-断言

断言:

   一个标准的用例都包含了断言,编写pytest自动化脚本的时候,也需要设置断言
   pytest常用断言比较大小与是否相等、是否包含、验证boolean

例子一:

    验证是否相等:
   import pytest
   def test_eq_1():
        assert 1==1
   class Test_cls:
        def test_eq_2(self):
            assert 2!=3
    def test_eq_3(self):
            assert 4>3
    def test_eq_4(self):
        assert 3<6
    def test_eq_5(self):
        assert 3==4
    if __name__ == '__main__':
        pytest.main(["-s","test_2.py"])

例子二:

    验证是否包含:
    import pytest
    def test_in_1():
        assert 'a' in 'abc'
    def test_in_2():
        assert 'c' in 'abd'
    if __name__ == '__main__':
        pytest.main(["-s","test_2.py"])

例子三:

    验证boolean
    import pytest
    def func(n):
    if n==10:
        return True
    else:
        return False
    def test_true_1():
        assert func(11)
    if __name__ == '__main__':
        pytest.main(["-s","test_2.py"])

参考:https://www.cnblogs.com/jerry-learn8/p/9770118.html

posted @ 2020-01-07 20:42  测试爬虫  阅读(146)  评论(0编辑  收藏  举报