11、pytest -- 测试的参数化

目录

往期索引:https://www.cnblogs.com/luizyao/p/11771740.html

在实际工作中,测试用例可能需要支持多种场景,我们可以把和场景强相关的部分抽象成参数,通过对参数的赋值来驱动用例的执行;

参数化的行为表现在不同的层级上:

另外,我们也可以通过pytest_generate_tests这个钩子方法自定义参数化的方案;

1. @pytest.mark.parametrize标记

@pytest.mark.parametrize的根本作用是在收集测试用例的过程中,通过对指定参数的赋值来新增被标记对象的调用(执行)

首先,我们来看一下它在源码中的定义:

# _pytest/python.py

def parametrize(self, argnames, argvalues, indirect=False, ids=None, scope=None):

着重分析一下各个参数:

  • argnames:一个用逗号分隔的字符串,或者一个列表/元组,表明指定的参数名;

    对于argnames,实际上我们是有一些限制的:

    • 只能是被标记对象入参的子集:

      @pytest.mark.parametrize('input, expected', [(1, 2)])
      def test_sample(input):
          assert input + 1 == 1

      test_sample中并没有声明expected参数,如果我们在标记中强行声明,会得到如下错误:

      In test_sample: function uses no argument 'expected'
    • 不能是被标记对象入参中,定义了默认值的参数:

      @pytest.mark.parametrize('input, expected', [(1, 2)])
      def test_sample(input, expected=2):
          assert input + 1 == expected

      虽然test_sample声明了expected参数,但同时也为其赋予了一个默认值,如果我们在标记中强行声明,会得到如下错误:

      In test_sample: function already takes an argument 'expected' with a default value
    • 会覆盖同名的fixture

      @pytest.fixture()
      def expected():
          return 1
      
      
      @pytest.mark.parametrize('input, expected', [(1, 2)])
      def test_sample(input, expected):
          assert input + 1 == expected

      test_sample标记中的expected(2)覆盖了同名的fixture expected(1),所以这条用例是可以测试成功的;

      这里可以参考:4、fixtures:明确的、模块化的和可扩展的 -- 在用例参数中覆写fixture

  • argvalues:一个可迭代对象,表明对argnames参数的赋值,具体有以下几种情况:

    • 如果argnames包含多个参数,那么argvalues的迭代返回元素必须是可度量的(即支持len()方法),并且长度和argnames声明参数的个数相等,所以它可以是元组/列表/集合等,表明所有入参的实参:

      @pytest.mark.parametrize('input, expected', [(1, 2), [2, 3], set([3, 4])])
      def test_sample(input, expected):
          assert input + 1 == expected

      注意:考虑到集合的去重特性,我们并不建议使用它;

    • 如果argnames只包含一个参数,那么argvalues的迭代返回元素可以是具体的值:

      @pytest.mark.parametrize('input', [1, 2, 3])
      def test_sample(input):
          assert input + 1
    • 如果你也注意到我们之前提到,argvalues是一个可迭代对象,那么我们就可以实现更复杂的场景;例如:从excel文件中读取实参:

      def read_excel():
          # 从数据库或者 excel 文件中读取设备的信息,这里简化为一个列表
          for dev in ['dev1', 'dev2', 'dev3']:
              yield dev
      
      
      @pytest.mark.parametrize('dev', read_excel())
      def test_sample(dev):
          assert dev

      实现这个场景有多种方法,你也可以直接在一个fixture中去加载excel中的数据,但是它们在测试报告中的表现会有所区别;

    • 或许你还记得,在上一篇教程(10、skip和xfail标记 -- 结合pytest.param方法)中,我们使用pytest.paramargvalues参数赋值:

      @pytest.mark.parametrize(
          ('n', 'expected'),
          [(2, 1),
          pytest.param(2, 1, marks=pytest.mark.xfail(), id='XPASS')])
      def test_params(n, expected):
          assert 2 / n == expected

      现在我们来具体分析一下这个行为:

      无论argvalues中传递的是可度量对象(列表、元组等)还是具体的值,在源码中我们都会将其封装成一个ParameterSet对象,它是一个具名元组(namedtuple),包含values, marks, id三个元素:

      >>> from _pytest.mark.structures import ParameterSet as PS
      >>> PS._make([(1, 2), [], None])
      ParameterSet(values=(1, 2), marks=[], id=None)

      如果直接传递一个ParameterSet对象会发生什么呢?我们去源码里找答案:

      # _pytest/mark/structures.py
      
      class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
      
          ...
      
          @classmethod
          def extract_from(cls, parameterset, force_tuple=False):
              """
              :param parameterset:
                  a legacy style parameterset that may or may not be a tuple,
                  and may or may not be wrapped into a mess of mark objects
      
              :param force_tuple:
                  enforce tuple wrapping so single argument tuple values
                  don't get decomposed and break tests
              """
      
              if isinstance(parameterset, cls):
                  return parameterset
              if force_tuple:
                  return cls.param(parameterset)
              else:
                  return cls(parameterset, marks=[], id=None)

      可以看到如果直接传递一个ParameterSet对象,那么返回的就是它本身(return parameterset),所以下面例子中的两种写法是等价的:

      # src/chapter-11/test_sample.py
      
      import pytest
      
      from _pytest.mark.structures import ParameterSet
      
      
      @pytest.mark.parametrize(
          'input, expected',
          [(1, 2), ParameterSet(values=(1, 2), marks=[], id=None)])
      def test_sample(input, expected):
          assert input + 1 == expected

      到这里,或许你已经猜到了,pytest.param的作用就是封装一个ParameterSet对象;那么我们去源码里求证一下吧!

      # _pytest/mark/__init__.py
      
      def param(*values, **kw):
          """Specify a parameter in `pytest.mark.parametrize`_ calls or
          :ref:`parametrized fixtures <fixture-parametrize-marks>`.
      
          .. code-block:: python
      
              @pytest.mark.parametrize("test_input,expected", [
                  ("3+5", 8),
                  pytest.param("6*9", 42, marks=pytest.mark.xfail),
              ])
              def test_eval(test_input, expected):
                  assert eval(test_input) == expected
      
          :param values: variable args of the values of the parameter set, in order.
          :keyword marks: a single mark or a list of marks to be applied to this parameter set.
          :keyword str id: the id to attribute to this parameter set.
          """
          return ParameterSet.param(*values, **kw)

      正如我们所料,现在你应该更明白怎么给argvalues传参了吧;

  • indirectargnames的子集或者一个布尔值;将指定参数的实参通过request.param重定向到和参数同名的fixture中,以此满足更复杂的场景;

    具体使用方法可以参考以下示例:

    # src/chapter-11/test_indirect.py
    
    import pytest
    
    
    @pytest.fixture()
    def max(request):
        return request.param - 1
    
    
    @pytest.fixture()
    def min(request):
        return request.param + 1
    
    
    # 默认 indirect 为 False
    @pytest.mark.parametrize('min, max', [(1, 2), (3, 4)])
    def test_indirect(min, max):
        assert min <= max
    
    
    # min max 对应的实参重定向到同名的 fixture 中
    @pytest.mark.parametrize('min, max', [(1, 2), (3, 4)], indirect=True)
    def test_indirect_indirect(min, max):
        assert min >= max
    
    
    # 只将 max 对应的实参重定向到 fixture 中
    @pytest.mark.parametrize('min, max', [(1, 2), (3, 4)], indirect=['max'])
    def test_indirect_part_indirect(min, max):
        assert min == max
  • ids:一个可执行对象,用于生成测试ID,或者一个列表/元组,指明所有新增用例的测试ID

    • 如果使用列表/元组直接指明测试ID,那么它的长度要等于argvalues的长度:

      @pytest.mark.parametrize('input, expected', [(1, 2), (3, 4)],
                        ids=['first', 'second'])
      def test_ids_with_ids(input, expected):
          pass

      搜集到的测试ID如下:

      collected 2 items
      <Module test_ids.py>
        <Function test_ids_with_ids[first]>
        <Function test_ids_with_ids[second]>
    • 如果指定了相同的测试IDpytest会在后面自动添加索引:

      @pytest.mark.parametrize('input, expected', [(1, 2), (3, 4)],
                        ids=['num', 'num'])
      def test_ids_with_ids(input, expected):
          pass

      搜集到的测试ID如下:

      collected 2 items
      <Module test_ids.py>
        <Function test_ids_with_ids[num0]>
        <Function test_ids_with_ids[num1]>
    • 如果在指定的测试ID中使用了非ASCII的值,默认显示的是字节序列:

      @pytest.mark.parametrize('input, expected', [(1, 2), (3, 4)],
                        ids=['num', '中文'])
      def test_ids_with_ids(input, expected):
          pass

      搜集到的测试ID如下:

      collected 2 items
      <Module test_ids.py>
        <Function test_ids_with_ids[num]>
        <Function test_ids_with_ids[\u4e2d\u6587]>

      可以看到我们期望显示中文,实际上显示的是\u4e2d\u6587

      如果我们想要得到期望的显示,该怎么办呢?去源码里找答案:

      # _pytest/python.py
      
      def _ascii_escaped_by_config(val, config):
          if config is None:
              escape_option = False
          else:
              escape_option = config.getini(
                  "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
              )
          return val if escape_option else ascii_escaped(val)

      我们可以通过在pytest.ini中使能disable_test_id_escaping_and_forfeit_all_rights_to_community_support选项来避免这种情况:

      [pytest]
      disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True

      再次搜集到的测试ID如下:

      <Module test_ids.py>
        <Function test_ids_with_ids[num]>
        <Function test_ids_with_ids[中文]>
    • 如果通过一个可执行对象生成测试ID

      def idfn(val):
          # 将每个 val 都加 1
          return val + 1
      
      
      @pytest.mark.parametrize('input, expected', [(1, 2), (3, 4)], ids=idfn)
      def test_ids_with_ids(input, expected):
          pass

      搜集到的测试ID如下:

      collected 2 items
      <Module test_ids.py>
        <Function test_ids_with_ids[2-3]>
        <Function test_ids_with_ids[4-5]>

      通过上面的例子我们可以看到,对于一个具体的argvalues参数(1, 2)来说,它被拆分为12分别传递给idfn,并将返回值通过-符号连接在一起作为一个测试ID返回,而不是将(1, 2)作为一个整体传入的;

      下面我们在源码中看看是如何实现的:

      # _pytest/python.py
      
      def _idvalset(idx, parameterset, argnames, idfn, ids, item, config):
          if parameterset.id is not None:
              return parameterset.id
          if ids is None or (idx >= len(ids) or ids[idx] is None):
              this_id = [
                  _idval(val, argname, idx, idfn, item=item, config=config)
                  for val, argname in zip(parameterset.values, argnames)
              ]
              return "-".join(this_id)
          else:
              return _ascii_escaped_by_config(ids[idx], config)

      和我们猜想的一样,先通过zip(parameterset.values, argnames)argnamesargvalues的值一一对应,再将处理过的返回值通过"-".join(this_id)连接;

      另外,如果我们足够细心,从上面的源码中还可以看出,假设已经通过pytest.param指定了id属性,那么将会覆盖ids中对应的测试ID,我们来证实一下:

      @pytest.mark.parametrize(
          'input, expected',
          [(1, 2), pytest.param(3, 4, id='id_via_pytest_param')],
          ids=['first', 'second'])
      def test_ids_with_ids(input, expected):
          pass

      搜集到的测试ID如下:

      collected 2 items
      <Module test_ids.py>
        <Function test_ids_with_ids[first]>
        <Function test_ids_with_ids[id_via_pytest_param]>

      测试IDid_via_pytest_param,而不是second

    讲了这么多ids的用法,对我们有什么用呢?

    我觉得,其最主要的作用就是更进一步的细化测试用例,区分不同的测试场景,为有针对性的执行测试提供了一种新方法;

    例如,对于以下测试用例,可以通过-k 'Window and not Non'选项,只执行和Windows相关的场景:

    # src/chapter-11/test_ids.py
    
    import pytest
    
    
    @pytest.mark.parametrize('input, expected', [
        pytest.param(1, 2, id='Windows'),
        pytest.param(3, 4, id='Windows'),
        pytest.param(5, 6, id='Non-Windows')
    ])
    def test_ids_with_ids(input, expected):
        pass
  • scope:声明argnames中参数的作用域,并通过对应的argvalues实例划分测试用例,进而影响到测试用例的收集顺序;

    • 如果我们显式的指明scope参数;例如,将参数作用域声明为模块级别:

      # src/chapter-11/test_scope.py
      
      import pytest
      
      
      @pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)], scope='module')
      def test_scope1(test_input, expected):
          pass
      
      
      @pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)], scope='module')
      def test_scope2(test_input, expected):
          pass

      搜集到的测试用例如下:

      collected 4 items
      <Module test_scope.py>
        <Function test_scope1[1-2]>
        <Function test_scope2[1-2]>
        <Function test_scope1[3-4]>
        <Function test_scope2[3-4]>

      以下是默认的收集顺序,我们可以看到明显的差别:

      collected 4 items
      <Module test_scope.py>
        <Function test_scope1[1-2]>
        <Function test_scope1[3-4]>
        <Function test_scope2[1-2]>
        <Function test_scope2[3-4]>
    • scope未指定的情况下(或者scope=None),当indirect等于True或者包含所有的argnames参数时,作用域为所有fixture作用域的最小范围;否者,其永远为function

      # src/chapter-11/test_scope.py
      
      @pytest.fixture(scope='module')
      def test_input(request):
          pass
      
      
      @pytest.fixture(scope='module')
      def expected(request):
          pass
      
      
      @pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)],
                              indirect=True)
      def test_scope1(test_input, expected):
          pass
      
      
      @pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)],
                              indirect=True)
      def test_scope2(test_input, expected):
          pass

      test_inputexpected的作用域都是module,所以参数的作用域也是module,用例的收集顺序和上一节相同:

      collected 4 items
      <Module test_scope.py>
        <Function test_scope1[1-2]>
        <Function test_scope2[1-2]>
        <Function test_scope1[3-4]>
        <Function test_scope2[3-4]>

1.1. empty_parameter_set_mark选项

默认情况下,如果@pytest.mark.parametrizeargnames中的参数没有接收到任何的实参的话,用例的结果将会被置为SKIPPED

例如,当python版本小于3.8时返回一个空的列表(当前Python版本为3.7.3):

# src/chapter-11/test_empty.py

import pytest
import sys


def read_value():
    if sys.version_info >= (3, 8):
        return [1, 2, 3]
    else:
        return []


@pytest.mark.parametrize('test_input', read_value())
def test_empty(test_input):
    assert test_input

我们可以通过在pytest.ini中设置empty_parameter_set_mark选项来改变这种行为,其可能的值为:

  • skip:默认值
  • xfail:跳过执行直接将用例标记为XFAIL,等价于xfail(run=False)
  • fail_at_collect:上报一个CollectError异常;

1.2. 多个标记组合

如果一个用例标记了多个@pytest.mark.parametrize标记,如下所示:

# src/chapter-11/test_multi.py

@pytest.mark.parametrize('test_input', [1, 2, 3])
@pytest.mark.parametrize('test_output, expected', [(1, 2), (3, 4)])
def test_multi(test_input, test_output, expected):
    pass

实际收集到的用例,是它们所有可能的组合:

collected 6 items
<Module test_multi.py>
  <Function test_multi[1-2-1]>
  <Function test_multi[1-2-2]>
  <Function test_multi[1-2-3]>
  <Function test_multi[3-4-1]>
  <Function test_multi[3-4-2]>
  <Function test_multi[3-4-3]>

1.3. 标记测试模块

我们可以通过对pytestmark赋值,参数化一个测试模块:

# src/chapter-11/test_module.py

import pytest

pytestmark = pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)])


def test_module(test_input, expected):
    assert test_input + 1 == expected

2. pytest_generate_tests钩子方法

pytest_generate_tests方法在测试用例的收集过程中被调用,它接收一个metafunc对象,我们可以通过其访问测试请求的上下文,更重要的是,可以使用metafunc.parametrize方法自定义参数化的行为;

我们先看看源码中是怎么使用这个方法的:

# _pytest/python.py

def pytest_generate_tests(metafunc):
    # those alternative spellings are common - raise a specific error to alert
    # the user
    alt_spellings = ["parameterize", "parametrise", "parameterise"]
    for mark_name in alt_spellings:
        if metafunc.definition.get_closest_marker(mark_name):
            msg = "{0} has '{1}' mark, spelling should be 'parametrize'"
            fail(msg.format(metafunc.function.__name__, mark_name), pytrace=False)
    for marker in metafunc.definition.iter_markers(name="parametrize"):
        metafunc.parametrize(*marker.args, **marker.kwargs)

首先,它检查了parametrize的拼写错误,如果你不小心写成了["parameterize", "parametrise", "parameterise"]中的一个,pytest会返回一个异常,并提示正确的单词;然后,循环遍历所有的parametrize的标记,并调用metafunc.parametrize方法;

现在,我们来定义一个自己的参数化方案:

在下面这个用例中,我们检查给定的stringinput是否只由字母组成,但是我们并没有为其打上parametrize标记,所以stringinput被认为是一个fixture

# src/chapter-11/test_strings.py

def test_valid_string(stringinput):
    assert stringinput.isalpha()

现在,我们期望把stringinput当成一个普通的参数,并且从命令行赋值:

首先,我们定义一个命令行选项:

# src/chapter-11/conftest.py

def pytest_addoption(parser):
    parser.addoption(
        "--stringinput",
        action="append",
        default=[],
        help="list of stringinputs to pass to test functions",
    )

然后,我们通过pytest_generate_tests方法,将stringinput的行为由fixtrue改成parametrize

# src/chapter-11/conftest.py

def pytest_generate_tests(metafunc):
    if "stringinput" in metafunc.fixturenames:
        metafunc.parametrize("stringinput", metafunc.config.getoption("stringinput"))

最后,我们就可以通过--stringinput命令行选项来为stringinput参数赋值了:

λ pipenv run pytest -q --stringinput='hello' --stringinput='world' src/chapter-11/test_strings.py
..                                                                     [100%] 
2 passed in 0.02s

如果我们不加--stringinput选项,相当于parametrizeargnames中的参数没有接收到任何的实参,那么测试用例的结果将会置为SKIPPED

λ pipenv run pytest -q src/chapter-11/test_strings.py
s                                                                  [100%] 
1 skipped in 0.02s

注意:

不管是metafunc.parametrize方法还是@pytest.mark.parametrize标记,它们的参数(argnames)不能是重复的,否者会产生一个错误:ValueError: duplicate 'stringinput'

原文地址:https://www.cnblogs.com/luizyao/p/11848352.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


目录1、前言2、mark的使用(一)注册自定义标记(二)在测试用例上标记(三)执行3、扩展(一)在同一个测试用例上使用多个标记(二)在测试类上使用标记1、前言在自动化测试工作中我们有时候并不需要测试所有的测试用例,比如在冒烟测试阶段,我们只需要测试基本功能是否正常就可以了。在pytest中提供
用例执行状态用例执行完成后,每条用例都有自己的状态,常见的状态有passed:测试通过failed:断言失败error:用例本身写的质量不行,本身代码报错(譬如:fixture不存在,fixture里面有报错)xfail:预期失败,加了 @pytest.mark.xfail()  error的栗子一:参数不存在 defpwd():prin
什么是conftest.py可以理解成一个专门存放fixture的配置文件 实际开发场景多个测试用例文件(test_*.py)的所有用例都需要用登录功能来作为前置操作,那就不能把登录功能写到某个用例文件中去了 如何解决上述场景问题?conftest.py的出现,就是为了解决上述问题,单独管理一些全局的
前言pytest默认执行用例是根据项目下的文件名称按ascii码去收集运行的;文件中的用例是从上往下按顺序执行的。pytest_collection_modifyitems这个函数顾名思义就是收集测试用例、改变用例的执行顺序的。【严格意义上来说,我们在用例设计原则上用例就不要有依赖顺序,这样才能更好
当我们对测试用例进行参数化时,使用@pytest.mark.parametrize的ids参数自定义测试用例的标题,当标题中有中文时,控制台和测试报告中会出现Unicode编码问题,这看起来特别像乱码,我们想让中文正常展示出来,需要用到pytest框架的钩子函数pytest_collection_modifyitems。先看问题:#file_n
前言:什么是元数据?元数据是关于数据的描述,存储着关于数据的信息,为人们更方便地检索信息提供了帮助。pytest框架里面的元数据可以使用pytest-metadata插件实现。文档地址https://pypi.org/project/pytest-metadata/未安装插件pytest-metadata之前执行:环境搭建:使用
前言前面一篇讲了setup、teardown可以实现在执行用例前或结束后加入一些操作,但这种都是针对整个脚本全局生效的如果有以下场景:用例1需要先登录,用例2不需要登录,用例3需要先登录。很显然无法用setup和teardown来实现了fixture可以让我们自定义测试用例的前置条件 
前言:写完一个项目的自动化用例之后,发现有些用例运行较慢,影响整体的用例运行速度,于是领导说找出运行慢的那几个用例优化下。--durations参数可以统计出每个用例运行的时间,对用例的时间做个排序。pytest-h查看命令行参数,关于--durations=N参数的使用方式--durations=N
钩子函数之pytest_addoption介绍:①pytest_addoption钩子函数可以让用户注册一个自定义的命令行参数,以便于用户在测试开始前将数据从外部(如:控制台)传递给程序;【程序根据获取的用户传递的自定义的参数值来做一些事情】②pytest_addoption钩子函数一般和内置fixturepytestcon
[pytest]#命令行参数----空格分隔,可添加多个命令行参数-所有参数均为插件包的参数addopts=-s-reruns1--html=..eporteport.html#测试路径----当前目录下的scripts文件夹-可自定义testpaths=../scripts#搜索文件名----当前目录下的scripts文件夹下,以test_开头,以.py
python通用测试框架大多数人用的是unittest+HTMLTestRunner,这段时间看到了pytest文档,发现这个框架和丰富的plugins很好用,所以来学习下pytest. image.pngpytest是一个非常成熟的全功能的Python测试框架,主要有以下几个特点:简单灵活,容易上手支持参数化能够支持简单的单
1、装饰器,放在函数前面,跳过用例 @pytest.mark.skip(reason="nowayofcurrentlytestingthis")importpytestdeftest1():print('操作1')print("-----------------------------------------------")@pytest.mark.skip(reason="nowayofcur
本文实例为大家分享了python下载微信公众号相关文章的具体代码,供大家参考,具体内容如下目的:从零开始学自动化测试公众号中下载“pytest"一系列文档1、搜索微信号文章关键字搜索2、对搜索结果前N页进行解析,获取文章标题和对应URL主要使用的是requests和bs4中的Beautifulsoup
From:https://www.jianshu.com/p/54b0f4016300一.fixture介绍fixture是pytest的一个闪光点,pytest要精通怎么能不学习fixture呢?跟着我一起深入学习fixture吧。其实unittest和nose都支持fixture,但是pytest做得更炫。fixture是pytest特有的功能,它用pytest.fixture标识,定义在函
参数化有两种方式:1、@pytest.mark.parametrize2、利用conftest.py里的pytest_generate_tests 1中的例子如下:@pytest.mark.parametrize("test_input,expected",[("3+5",8),("2+4",6),("6*9",42)])deftest_eval(test_input,expected):
pytest优于其他测试框架的地方:1、简单的测试可以简单的写2、复杂的测试也可以简单的写3、测试的可读性强4、易于上手5、断言失败仅使用原生assert关键字,而不是self.assertEqual()或者self.assertLessThan()6、pytest可以运行有unitest和nose编写的测试用例pytest不依赖pyth
学习python的pytest框架需要的基础知识和学习准备测试从业者学习python应该掌握的内容:首先是变量和数据类型,其次列表、字典以及Json的一些处理,再者就是循环判断以及函数或类这些内容。其中的重点:1.循环判断以及字典这块是重点2.函数和类,类的学习这块要花较多时间去学
前言pytest可以支持自定义标记,自定义标记可以把一个web项目划分多个模块,然后指定模块名称执行。app自动化的时候,如果想android和ios公用一套代码时,也可以使用标记功能,标明哪些是ios用例,哪些是android的,运行代码时候指定mark名称运行就可以mark标记1.以下用例,标记test_send_http(
unittest参考文档: https://docs.python.org/3/library/unittest.htmlunittest笔记TheunittestunittestingframeworkwasoriginallyinspiredbyJUnitandhasasimilarflavorasmajorunittestingframeworksinotherlanguages.Itsupportstestautomation,shar
fixture场景一:参数传入代码如下:运行结果: