pytest---多重断言(pytest-assume)

前言

在编写自动化测试用例的时候,可能一条用例存在这多条断言,那么在自动化中如何编写多条断言且断言失败后还能继续往下执行?这里引入新的插件pytest-assume

pytest-assume

pytest-assume:属于pytest的插件,可以在用例中使用多个断言,且断言时候后不影响其他的断言

安装:pip install pytest-assume

源码:https://github.com/astraw38/pytest-assume

使用方法和普通的断言方式一样,唯一区别就是断言失败后,可以继续执行。

正常断言(assert)

# coding:utf-8

import pytest
class Test_01:
    def test_01(self):
        print('---用例01---')
        assert 1 == 1
        assert 1 == 2
        print('执行成功')
    def test_02(self):
        print('---用例02---')
    def test_03(self):
        print('---用例03---')

通过cmd运行执行后,可以看出来,当断言失败后,就不会继续往下执行了。

pytest---多重断言(pytest-assume)_第1张图片

多重断言(pytest-assume)

# coding:utf-8
import pytest
class Test_01:

    def test_01(self):
        print('---用例01---')
        pytest.assume(1 == 1)
        pytest.assume(1 == 2)
        print('执行成功')

    def test_02(self):
        print('---用例02---')

    def test_03(self):
        print('---用例03---')

通过cmd运行执行,查看当前执行结果会发现,我们的多重断言在前面的断言失败后,会继续往下运行,不会因为断言失败,而不继续往下运行

pytest---多重断言(pytest-assume)_第2张图片

你可能感兴趣的:(pytest,python,开发语言)