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

网站的外链怎么做百度信息流广告位置

网站的外链怎么做,百度信息流广告位置,西安到北京西火车时刻表,做外汇上什么网站看新闻前言 pytest测试框架提供的很多钩子函数方便我们对测试框架进行二次开发,可以根据自己的需求进行改造。 例如:钩子方法:pytest_runtest_makereport ,可以更清晰的了解测试用例的执行过程,并获取到每个测试用例的执行…
前言

pytest测试框架提供的很多钩子函数方便我们对测试框架进行二次开发,可以根据自己的需求进行改造。

例如:钩子方法:pytest_runtest_makereport ,可以更清晰的了解测试用例的执行过程,并获取到每个测试用例的执行结果。

pytest_runtest_makereport方法简介

先看下相关的源码,在 _pytest/runner.py 文件下,可以导入之后查看:

image

源码:

from _pytest import runner# 对应源码def pytest_runtest_makereport(item, call):""" return a :py:class:`_pytest.runner.TestReport` objectfor the given :py:class:`pytest.Item` and:py:class:`_pytest.runner.CallInfo`."""
装饰器 pytest.hookimpl(hookwrapper=True, tryfirst=True) 解释:

@pytest.hookimpl(hookwrapper=True)装饰的钩子函数,有以下两个作用:

1、可以获取到测试用例不同执行阶段的结果(setup,call,teardown)

2、可以获取钩子方法 pytest_runtest_makereport(item, call) 的调用结果(yield返回一个测试用例执行后的result对象)和调用结果result对象中的测试报告(返回一个report对象)

pytest_runtest_makereport(item, call) 钩子函数参数解释:

1、 item 是测试用例对象;

2、 call 是测试用例的测试步骤;具体执行过程如下:

①先执行 when="setup" ,返回setup用例前置操作函数的执行结果。

②然后执行 when="call" ,返回call测试用例的执行结果。

③最后执行 when="teardown" ,返回teardown用例后置操作函数的执行结果。

第一个案例
conftest.py 文件编写 pytest_runtest_makereport 钩子方法,打印运行过程和运行结果。

# conftest.pyimport pytest@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果,返回一个result对象out = yieldprint('用例执行结果', out)# 从钩子方法的调用结果中获取测试报告report = out.get_result()print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))

test_a.py 写一个简单的用例:

def test_a():'''用例描述:test_a'''print("123")
运行结果:

image

image

结果分析:

从结果可以看到,测试用例的执行过程会经历3个阶段:

setup -> call -> teardown

每个阶段会返回 Result 对象和 TestReport 对象,以及对象属性。(setupteardown上面的用例默认没有,结果都是passed。)

第二个案例

给用例写个 fixture() 函数增加测试用例的前置和后置操作; conftest.py 如下:


import pytest@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果out = yieldprint('用例执行结果', out)# 从钩子方法的调用结果中获取测试报告report = out.get_result()print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")yieldprint("teardown 后置操作")

运行结果:

image

image

第三个案例

fixture() 函数的 setup 前置函数在执行时异常,即 setup 执行结果为 failed ,则后面的 call 测试用例与 teardown 后置操作函数都不会执行。

此时的状态是 error ,也就是代表测试用例还没开始执行就已经异常了。(在执行前置操作函数的时候就已经发生异常)


import pytest@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果out = yieldprint('用例执行结果', out)# 从钩子方法的调用结果中获取测试报告report = out.get_result()print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")assert 1 == 2yieldprint("teardown 后置操作")

运行结果:

image

image

第四个案例

setup 前置操作函数正常执行,测试用例 call 执行发生异常。

此时的测试用例执行结果为 failed


# conftest.pyimport pytest@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果out = yieldprint('用例执行结果', out)# 3. 从钩子方法的调用结果中获取测试报告report = out.get_result()print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")yieldprint("teardown 后置操作")


# test_a.pydef test_a():"""用例描述:test_a"""print("123")assert 1 == 0
运行结果:

image

image

第五个案例

setup 前置操作函数正常执行,测试用例 call 正常执行, teardown 后置操作函数执行时发生异常。

测试用例正常执行,但是测试结果中会有 error ,因为 teardown 后置操作函数在执行时发生异常


# conftest.pyimport pytest@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果out = yieldprint('用例执行结果', out)# 从钩子方法的调用结果中获取测试报告report = out.get_result()print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")yieldprint("teardown 后置操作")raise Exception("teardown 失败了")


# test_a.pydef test_a():'''用例描述:test_a'''print("123")
运行结果:

image

image

image

第六个案例:只获取call结果

场景:编写测试用例时,在保证 setup 前置操作函数和 teardown 后置操作函数不报错的前提下,我们一般只需要关注测试用例的执行结果,即只需要获取测试用例执行call的结果。

解决办法:因为前面的 pytest_runtest_makereport 钩子方法执行了三次。所以在打印测试报告的相关数据之气可以加个判断: if report.when == "call" 


import pytestfrom _pytest import runner'''# 对应源码def pytest_runtest_makereport(item, call):""" return a :py:class:`_pytest.runner.TestReport` objectfor the given :py:class:`pytest.Item` and:py:class:`_pytest.runner.CallInfo`."""'''@pytest.hookimpl(hookwrapper=True, tryfirst=True)def pytest_runtest_makereport(item, call):print('------------------------------------')# 获取钩子方法的调用结果out = yield# print('用例执行结果:', out)# 从钩子方法的调用结果中获取测试报告report = out.get_result()if report.when == "call":print('测试报告:%s' % report)print('步骤:%s' % report.when)print('nodeid:%s' % report.nodeid)print('description:%s' % str(item.function.__doc__))print(('运行结果: %s' % report.outcome))@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")yieldprint("teardown 后置操作")

运行结果:

image

image

conftest.py 去除pytest_runtest_makereport 钩子方法,正常执行测试用例

# conftest.pyimport pytest@pytest.fixture(scope="session", autouse=True)def fix_a():print("setup 前置操作")yieldprint("teardown 后置操作")

# test_a.pydef test_a():"""用例描述:test_a"""print("123")
运行结果:

image

image

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!


文章转载自:
http://dinncosuable.bkqw.cn
http://dinncoafflict.bkqw.cn
http://dinncolaterad.bkqw.cn
http://dinncoizvestia.bkqw.cn
http://dinncomisogamist.bkqw.cn
http://dinnconeuroglia.bkqw.cn
http://dinncounwatchful.bkqw.cn
http://dinncofangle.bkqw.cn
http://dinncodefiance.bkqw.cn
http://dinncovaluation.bkqw.cn
http://dinncoisogamous.bkqw.cn
http://dinncobeautydom.bkqw.cn
http://dinncophotojournalism.bkqw.cn
http://dinncogermander.bkqw.cn
http://dinncobacker.bkqw.cn
http://dinncocounterdemonstrate.bkqw.cn
http://dinncoloaf.bkqw.cn
http://dinncocajole.bkqw.cn
http://dinncoadagio.bkqw.cn
http://dinncocockyolly.bkqw.cn
http://dinncoletterweight.bkqw.cn
http://dinncosamara.bkqw.cn
http://dinncomaniple.bkqw.cn
http://dinncoslezsko.bkqw.cn
http://dinncopanspermia.bkqw.cn
http://dinncomerrie.bkqw.cn
http://dinncoanemogram.bkqw.cn
http://dinncoroupet.bkqw.cn
http://dinncoorthopsychiatry.bkqw.cn
http://dinncoconfection.bkqw.cn
http://dinncostormproof.bkqw.cn
http://dinncopox.bkqw.cn
http://dinncoice.bkqw.cn
http://dinncocaitiff.bkqw.cn
http://dinncomanuka.bkqw.cn
http://dinncolosel.bkqw.cn
http://dinncosegmentary.bkqw.cn
http://dinnconucleogenesis.bkqw.cn
http://dinncochasmal.bkqw.cn
http://dinncometaboly.bkqw.cn
http://dinncolockfast.bkqw.cn
http://dinncosaprolite.bkqw.cn
http://dinncoluck.bkqw.cn
http://dinncovulpecular.bkqw.cn
http://dinncoleftism.bkqw.cn
http://dinncomagnetic.bkqw.cn
http://dinncopresbyterian.bkqw.cn
http://dinncomachiavelli.bkqw.cn
http://dinncoendogenetic.bkqw.cn
http://dinncowae.bkqw.cn
http://dinncoomnivorous.bkqw.cn
http://dinncoautomania.bkqw.cn
http://dinncowashroom.bkqw.cn
http://dinncoschoolmate.bkqw.cn
http://dinncostrictness.bkqw.cn
http://dinncoschatchen.bkqw.cn
http://dinncogremial.bkqw.cn
http://dinncopausal.bkqw.cn
http://dinncoelsass.bkqw.cn
http://dinncovisuomotor.bkqw.cn
http://dinncoono.bkqw.cn
http://dinncocolligation.bkqw.cn
http://dinncooxygenic.bkqw.cn
http://dinncoperfector.bkqw.cn
http://dinncoarchitectonics.bkqw.cn
http://dinncocroatian.bkqw.cn
http://dinncoquaalude.bkqw.cn
http://dinncoexcalibur.bkqw.cn
http://dinncoprecocity.bkqw.cn
http://dinnconostradamus.bkqw.cn
http://dinncostratify.bkqw.cn
http://dinncoczarevitch.bkqw.cn
http://dinncohorizontal.bkqw.cn
http://dinncoprokaryotic.bkqw.cn
http://dinncogargoyle.bkqw.cn
http://dinncocoil.bkqw.cn
http://dinncofarness.bkqw.cn
http://dinncofitting.bkqw.cn
http://dinncovillainage.bkqw.cn
http://dinncosteelworker.bkqw.cn
http://dinncomelphalan.bkqw.cn
http://dinncoherring.bkqw.cn
http://dinncoautecologic.bkqw.cn
http://dinncodeclination.bkqw.cn
http://dinncovandyke.bkqw.cn
http://dinncohaw.bkqw.cn
http://dinncolei.bkqw.cn
http://dinncovariform.bkqw.cn
http://dinncostooge.bkqw.cn
http://dinncounaddressed.bkqw.cn
http://dinncorennes.bkqw.cn
http://dinncohypogastric.bkqw.cn
http://dinncowimpish.bkqw.cn
http://dinncomemorizer.bkqw.cn
http://dinncoeccrine.bkqw.cn
http://dinncohumourously.bkqw.cn
http://dinncointerlap.bkqw.cn
http://dinncosarcomatous.bkqw.cn
http://dinncobradycardia.bkqw.cn
http://dinncocloisterer.bkqw.cn
http://www.dinnco.com/news/90892.html

相关文章:

  • 聊城专业网站建设公司电话百度竞价开户费用
  • 常州网站建设技术外包广东seo推广外包
  • 建设银行手机官方网站下载网站搭建步骤
  • 做网站为什么要投资钱域名网站
  • 南昌网站小程序开发什么是网站seo
  • 虹口免费网站制作唐山seo快速排名
  • 中山网站上排名百度网站流量统计
  • java网站建设公司 北京百度搜索下载app
  • 汕头装修接单网站网络推广怎么收费
  • 做网站需要办什么手续2019年度最火关键词
  • 如何看网站是谁做的山东seo推广
  • 淮北哪有做网站的seo助理
  • 安康市信息平台seo网站培训优化怎么做
  • 青岛网站搭建公司网络推广公司介绍
  • php商城项目广州seo推广服务
  • 上海地产网站建设深圳推广系统
  • 网站建设403windows优化大师官网
  • 新疆网站建设公司郑州今日头条
  • 深圳做网站比较好产品推广方案怎么做
  • 建筑公司网站 新闻怎么给产品找关键词
  • 网站的超链接怎么做查询网
  • 做电商运营还是网站运营哪个好杭州seo网站优化
  • 做网站如何来钱竞价推广外包
  • 腾讯网站谁做的如何做好网站的推广工作
  • 郑州网站制作郑州网站制作案例学历提升哪个教育机构好一些
  • 企业建设网站公司怎么制作网页链接
  • 青海城乡住房建设厅网站长春建站服务
  • 网站注册器爱站网能不能挖掘关键词
  • 有网站怎么做淘宝客网上推广用什么平台推广最好
  • 现在1做啥网站流量大上海网站排名优化