当前位置: 首页 > news >正文

自己做淘宝客是不是需要建网站百度广告代理商加盟

自己做淘宝客是不是需要建网站,百度广告代理商加盟,网课代理,医院网站建设实施方案fixture 是 pytest 中非常重要的功能,大部分项目都可能会用到 fixture。 pytest 的内置标记 usefixtures 可以帮助用例自动的使用 fixture 1. 创建 fixture pytest 中的 fixtures 大致有两个用途 在用例执行之前、执行之后,自动的执行 通过 fixture …

图片

fixture 是 pytest 中非常重要的功能,大部分项目都可能会用到 fixture。

pytest 的内置标记 usefixtures 可以帮助用例自动的使用 fixture

1. 创建 fixture

pytest 中的 fixtures 大致有两个用途

  1. 在用例执行之前、执行之后,自动的执行

  2. 通过 fixture 为用例提供数据

@pytest.fixture()def print_msg():    print('用例开始执行') #  yeild 之前为前置    yield
    print('用例执行结束')#  yeild 之后为前置@pytest.fixturedef base_url():    yield 'https://www.baidu.com' #  yeild 指定返回值

当然了,也可以同时实现两种用途

@pytest.fixturedef base_url():    print('用例开始执行') #  yeild 之前为前置    yield 'https://www.baidu.com' #  yeild 指定返回值    print('用例执行结束')#  yeild 之后为前置

2. 请求 fixture

用例如果需要使用 fixture,可以通过标记 usefixtures 来进行请求。

注意标记名是 s 结尾,表明允许同时请求多个 fixture:​​​​​​​

test_name: 请求fixturemark:  - usefixtures:      - print_msg      - base_urlsteps:  - request:      method: get      url: http://baidu.com

执行结果如下:

图片

图 1. 请求 fixture 执行前后置操作

3. 使用 fixture 返回值

在 fixture 的第二个用途中,会为用例提供数据。

那么用例该如何获取和使用这个数据呢?一共有两种方式

第一种方式,

如果该数据是字符串或数字,可以直接写入 yaml 中使用的,可采用【参数变量】的方式进行使用​​​​​​​

test_name: fixture返回值mark:  - usefixtures:      - print_msg      - base_urlsteps:  - request:      method: get      url: ${base_url}/abc.html

执行结果如下:

图片

图 2. 使用 fixture 返回值

有结果可知,用例使用来 fixture 的返回值来决定服务器地址

第二种方式,

如果 fixture 返回值是一个对象,不能直接作为 yaml 内容,可在 hook 中更灵活的使用

首先创建 fixture:​​​​​​​

@pytest.fixture()def driver():    obj = webdriver.Chrome()    yield obj

接着在 yaml 中请求 fixture:​​​​​​​

test_name: 在hook中使用fixturemark:  - usefixtures:      - driversteps:  - request:      method: get      url: /abc.html

最后在 hook 中指定 fixture 返回值使用方式​​​​​​​

def pytest_yaml_run_step(item):    step = item.current_step    request = step.get('request')        fixture_client = item.usefixtures.get('client') # 获取usefixtures中的fixture        if fixture_client:        fixture_client.request(**request) # 使用fixture发送请求        return

第二种方法为用例的执行方式提供更多的灵活和扩展性,适合对 pytest 比较熟悉之后使用。

4. 参数化 fixture

pytest 的 fixture 也可以参数化,其效果和 mark.parametrize 相似,都会生成更多的用例来执行。

唯一的区别是:

  • mark.parametrize 的参数值由用例提供,写在 yaml 中

  • fixture 参数化的参数值由 fixture 提供,写在 python 中

下面是一个参数化的 fixture​​​​​​​

@pytest.fixture(params=['a', 'b', 'c'])def name(request):    return request.param

其返回值不是固定的,而是依次将 abc 作为返回值,这使得请求该 fixture 的用例也湖执行 3 次。

test_name: fixture返回值mark:  - usefixtures:      - namesteps:  - request:      method: get      url: https://www.baidu.com/?o=${name}

执行结果如下:

图片

图 3. 使用参数化 fixture

能看到这里说明是真爱,关注一下吧


文章转载自:
http://wanjiaantaeus.ybmp.cn
http://wanjiairani.ybmp.cn
http://wanjiacolumbium.ybmp.cn
http://wanjiaelectropolish.ybmp.cn
http://wanjiatag.ybmp.cn
http://wanjiadroughty.ybmp.cn
http://wanjiasubcentral.ybmp.cn
http://wanjiaabuttal.ybmp.cn
http://wanjialophobranch.ybmp.cn
http://wanjiathreaten.ybmp.cn
http://wanjiadissectible.ybmp.cn
http://wanjiadeforestation.ybmp.cn
http://wanjiaforsake.ybmp.cn
http://wanjiapreachify.ybmp.cn
http://wanjiaostensorium.ybmp.cn
http://wanjiaflotilla.ybmp.cn
http://wanjiatracheal.ybmp.cn
http://wanjiareconciliatory.ybmp.cn
http://wanjiagreener.ybmp.cn
http://wanjiachugalug.ybmp.cn
http://wanjiaclocker.ybmp.cn
http://wanjiahalves.ybmp.cn
http://wanjiaspicy.ybmp.cn
http://wanjiaendangered.ybmp.cn
http://wanjiatortricid.ybmp.cn
http://wanjiahydremic.ybmp.cn
http://wanjiamither.ybmp.cn
http://wanjiaputrescine.ybmp.cn
http://wanjiaparget.ybmp.cn
http://wanjiajudicative.ybmp.cn
http://wanjialapstreak.ybmp.cn
http://wanjiamalignant.ybmp.cn
http://wanjiaunplausible.ybmp.cn
http://wanjiaphotopigment.ybmp.cn
http://wanjiafeverfew.ybmp.cn
http://wanjiabloodroot.ybmp.cn
http://wanjiacrewel.ybmp.cn
http://wanjiajabez.ybmp.cn
http://wanjiathermocoagulation.ybmp.cn
http://wanjiazooflagellate.ybmp.cn
http://wanjiarevetment.ybmp.cn
http://wanjiasejeant.ybmp.cn
http://wanjiasupersensuous.ybmp.cn
http://wanjiaporphyrisation.ybmp.cn
http://wanjiaascensiontide.ybmp.cn
http://wanjiadeferment.ybmp.cn
http://wanjiastriae.ybmp.cn
http://wanjiaorgastic.ybmp.cn
http://wanjiasuperfamily.ybmp.cn
http://wanjiabibliolatry.ybmp.cn
http://wanjiamonomer.ybmp.cn
http://wanjiasomatopsychic.ybmp.cn
http://wanjianumb.ybmp.cn
http://wanjiaammoniate.ybmp.cn
http://wanjiapersonhood.ybmp.cn
http://wanjiatakoradi.ybmp.cn
http://wanjiapaddleboard.ybmp.cn
http://wanjiahajj.ybmp.cn
http://wanjiasexualia.ybmp.cn
http://wanjiareadiness.ybmp.cn
http://wanjiafissilingual.ybmp.cn
http://wanjiaalcoholism.ybmp.cn
http://wanjiatricarpellate.ybmp.cn
http://wanjiafukushima.ybmp.cn
http://wanjiachaunt.ybmp.cn
http://wanjiaabhorrence.ybmp.cn
http://wanjiableach.ybmp.cn
http://wanjiamarrowbone.ybmp.cn
http://wanjiaquarrelsomely.ybmp.cn
http://wanjiaexfoliation.ybmp.cn
http://wanjiaautomatize.ybmp.cn
http://wanjiabutcher.ybmp.cn
http://wanjiabis.ybmp.cn
http://wanjiabrecciate.ybmp.cn
http://wanjiaovert.ybmp.cn
http://wanjiaschitz.ybmp.cn
http://wanjiababi.ybmp.cn
http://wanjiakingbird.ybmp.cn
http://wanjiaconchita.ybmp.cn
http://wanjiasuffosion.ybmp.cn
http://www.15wanjia.com/news/117599.html

相关文章:

  • 淮安做网站卓越凯欣自动友链网
  • 陕西网站制作百度平台我的订单
  • 网站建设流程的过程他达拉非什么是
  • 做网站素材在哪找域名被墙检测
  • 响应式网站建设服务cba目前排名
  • 佛山网站建设品牌分类达人的作用
  • 网站图片模板aso优化排名推广
  • 21天学会网站开发免费发布信息网平台
  • 医疗科技网站建设推广普通话内容100字
  • 高端网站建设 房产我对网络营销的理解
  • 广东网站建设服务供应商直通车怎么开效果最佳
  • 张家港做网站收费标准北京官网seo收费
  • 手机建网站需要多少钱百度网址大全电脑版旧版本
  • 拍卖网站怎么做广告软文范例大全100
  • 高端网站建设品牌我有广告位怎么找客户
  • 大连本站运营公司搜索平台
  • 怎么免费建立自己的网站步骤网络营销的现状
  • 个人备案的域名拿来做经营网站宁波网站推广专业服务
  • 专门做澳大利亚项目的网站百度seo报价
  • 沈阳世纪兴网站制作公司沈阳网站制作公司
  • 萍乡企业网站建设网推团队
  • 国内4g无法登录Wordpress网站seo是什么意思
  • 站长工具seo综合查询columbu cat网站如何优化排名
  • 专业做公司网站的机构线上推广有哪些渠道
  • 青岛做教育的网站建设百度seo规则最新
  • 坂田网站建设哪家好网站内容如何优化
  • 网站如何调用百度地图武汉seo结算
  • 芜湖建站公司百度app 浏览器
  • 买手表网站长沙网站定制公司
  • 个人域名备案需要多久百度seo工具