当前位置:网站首页>pytest接口自动化测试框架 | parametrize源码解析
pytest接口自动化测试框架 | parametrize源码解析
2022-08-01 07:12:00 【COCOgsta】
视频来源: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:
"""
边栏推荐
猜你喜欢
MVVM项目开发(商品管理系统一)
爬虫框架 Scrapy 详解
【MySQL】操作表DML相关语句
支付宝如何生成及配置公钥证书
LevelSequence源码分析
MySQL row locks and gap locks
Self-made a remote control software - VeryControl
Introduction to the basic principles, implementation and problem solving of crawler
Zero-code website development tool: WordPress
Golang: go get url and form attribute value
随机推荐
13 - JUC CountDownLatch concurrent programming
NIO programming
我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
小程序通过云函数操作数据库【使用get取数据库】
Leetcode第 304 场周赛
The BP neural network based on MATLAB voice characteristic signal classification
电磁兼容简明教程(6)测试项目
支付宝如何生成及配置公钥证书
关于App不同方式更新的测试点归纳
Guest brush SQL - 2
LeetCode240+312+394
rhcsa 第四天
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的pad_fn函数与gt::fmt函数一起用于填充包含数值的特定列、对数据列的数值进行十进制对齐(从小数点对齐)
我的创作纪念日
Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
阿里三面:MQ 消息丢失、重复、积压问题,该如何解决?
The use of Golang: go template engine
拳头游戏免版权音乐下载,英雄联盟无版权音乐,可用于视频创作、直播
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
2022杭电多校第二场1011 DOS Card(线段树)