pytest接口自动化测试框架 | parametrize源码解析

视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》

一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!

附上汇总贴:pytest接口自动化测试框架 | 汇总_COCOgsta的博客-CSDN博客


def paramtrize(argnames, argvalues, indirect=False, ids=None, scope=None,
               *, _param_mark=None):
    """
    Add new invocations to the underlying test function using the list of
    argvalues for the given argnames. Parametrization is performed during
    the collection phase. If you need to setup expensive resources see about
    setting indirect to do it rather at test setup time.
    # 使用给定argnames的argValue列表向基础测试函数添加新的调用。在收集阶段(理解为用例执行阶段)
    执行参数化。

    :param argnames: (Union[str, List[str], Tuple[str, ..]]) - A comma-separated
    string denoting one or more argument names, or a list/tuple of argument strings.
    # 参数名:使用用逗号分隔的字符串,或列表或元组,表示一个或多个参数名

    :param argvalues: (Iterable[Union[_pytest.mark.structures.ParameterSet,
    Sequence[ojbect], object]]) -
    The list of argvalues determines how often a test is invoked with different argument
    values.
    If only one argname was specified argvalues is a list of values. If N argnames were
    specified, argvalues must be a list of N-tuples, where each tuple-element specifies
    a value for its respective argname.
    # 参数值:只有一个argnames,argvalues则是值列表。有N个argnames时,
    每个元组对应一组argnames,所有元组组合成一个列表

    :param indirect: (Union[bool, Sequence[str]]) - A list of arguments' names
    (subset of argnames) or a boolean. If True the list contains all names from
    the argnames. Each argvalue corresponding to an argname in this list will be
    passed as request.param to its respective argname fixture function so that it
    can perform more expensive setups during the setup phase of a test rather than
    at collection time.
    # indirect:当indirect=True时,若传入的argnames是fixture函数名。
    # 此时fixutre函数名将成为一个可执行的函数,argvalues作为fixture的参数,执行fixture函数,
    最终结果再存入request.param;
    当indirect=False时,fixture函数只作为一个参数名给测试收集阶段调用。
    什么是the setup phase 测试设置阶段?理解为配置conftest.py阶段
    什么是the collection phase 测试收集阶段?理解为用例执行阶段

    :param ids: (Optional[Union[Iterable[Union[None, str, float, int, bool]],
    Callable[[Any], Optional[Object]]]]) -
    Sequence of (or generator for) ids for argvalues, or a callable to return part of
    the id for each argvalue.
    With sequences (and generators like itertools.count()) the returned ids should be
    of type string, int, float, bool, or None. They are mapped to the corresponding
    index in argvalues. None means to use the auto-generated id.
    If it is a callable it will be called for each entry in argvalues,
    and the return value is used as part of the auto-generated id for the whole
    set (where parts are joined with dashes ("-")). This is useful to provide more
    specific ids for certain items, e.g. dates. Returning None will use an
    auto-generated id.
    If no ids are provided they will be generated automatically from the argvalues.
    # ids:字符串列表,可以理解为标题,与用例个数保持一致

    :param scope: (Optional[_Scope]) - If specified it denotes the scope of the
    parameters. The scope is used for grouping tests by parameter instance.
    It will also override any fixture-function defined scope, allowing to set
    a dynamic scope using test context or configuration.
    # 如果指定,则表示参数的范围。作用域用于按参数实例对测试进行分组。它还将覆盖任何fixture函数
    定义的范围,允许使用测试上下文或配置动态范围。

    :param _param_mark:
    :return:
    """
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值