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

网站建设属于IT吗和男朋友都是第一次做网站

网站建设属于IT吗,和男朋友都是第一次做网站,短视频运营培训学费多少,龙岩网站建设套餐服务前言 pytest测试框架提供的很多钩子函数方便我们对测试框架进行二次开发#xff0c;可以根据自己的需求进行改造。 例如#xff1a;钩子方法#xff1a;pytest_runtest_makereport #xff0c;可以更清晰的了解测试用例的执行过程#xff0c;并获取到每个测试用例的执行…前言 pytest测试框架提供的很多钩子函数方便我们对测试框架进行二次开发可以根据自己的需求进行改造。 例如钩子方法pytest_runtest_makereport 可以更清晰的了解测试用例的执行过程并获取到每个测试用例的执行结果。 pytest_runtest_makereport方法简介 先看下相关的源码在 _pytest/runner.py 文件下可以导入之后查看 源码 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(hookwrapperTrue, tryfirstTrue) 解释 pytest.hookimpl(hookwrapperTrue)装饰的钩子函数有以下两个作用 1、可以获取到测试用例不同执行阶段的结果setupcallteardown 2、可以获取钩子方法 pytest_runtest_makereport(item, call) 的调用结果yield返回一个测试用例执行后的result对象和调用结果result对象中的测试报告返回一个report对象 pytest_runtest_makereport(item, call) 钩子函数参数解释 1、 item 是测试用例对象 2、 call 是测试用例的测试步骤具体执行过程如下 ①先执行 whensetup 返回setup用例前置操作函数的执行结果。 ②然后执行 whencall 返回call测试用例的执行结果。 ③最后执行 whenteardown 返回teardown用例后置操作函数的执行结果。 第一个案例 conftest.py 文件编写 pytest_runtest_makereport 钩子方法打印运行过程和运行结果。 # conftest.pyimport pytestpytest.hookimpl(hookwrapperTrue, tryfirstTrue)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_aprint(123) 运行结果 结果分析 从结果可以看到测试用例的执行过程会经历3个阶段 setup - call - teardown每个阶段会返回 Result 对象和 TestReport 对象以及对象属性。setup和teardown上面的用例默认没有结果都是passed。 第二个案例 给用例写个 fixture() 函数增加测试用例的前置和后置操作 conftest.py 如下 import pytestpytest.hookimpl(hookwrapperTrue, tryfirstTrue)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(scopesession, autouseTrue)def fix_a():print(setup 前置操作)yieldprint(teardown 后置操作) 运行结果 第三个案例 fixture() 函数的 setup 前置函数在执行时异常即 setup 执行结果为 failed 则后面的 call 测试用例与 teardown 后置操作函数都不会执行。 此时的状态是 error 也就是代表测试用例还没开始执行就已经异常了。在执行前置操作函数的时候就已经发生异常 import pytestpytest.hookimpl(hookwrapperTrue, tryfirstTrue)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(scopesession, autouseTrue)def fix_a():print(setup 前置操作)assert 1 2yieldprint(teardown 后置操作) 运行结果 第四个案例 setup 前置操作函数正常执行测试用例 call 执行发生异常。 此时的测试用例执行结果为 failed # conftest.pyimport pytestpytest.hookimpl(hookwrapperTrue, tryfirstTrue)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(scopesession, autouseTrue)def fix_a():print(setup 前置操作)yieldprint(teardown 后置操作) # test_a.pydef test_a():用例描述:test_aprint(123)assert 1 0 运行结果 第五个案例 setup 前置操作函数正常执行测试用例 call 正常执行 teardown 后置操作函数执行时发生异常。 测试用例正常执行但是测试结果中会有 error 因为 teardown 后置操作函数在执行时发生异常 # conftest.pyimport pytestpytest.hookimpl(hookwrapperTrue, tryfirstTrue)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(scopesession, autouseTrue)def fix_a():print(setup 前置操作)yieldprint(teardown 后置操作)raise Exception(teardown 失败了) # test_a.pydef test_a():用例描述:test_aprint(123) 运行结果 第六个案例只获取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(hookwrapperTrue, tryfirstTrue)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(scopesession, autouseTrue)def fix_a():print(setup 前置操作)yieldprint(teardown 后置操作) 运行结果 conftest.py 去除pytest_runtest_makereport 钩子方法正常执行测试用例 # conftest.pyimport pytestpytest.fixture(scopesession, autouseTrue)def fix_a():print(setup 前置操作)yieldprint(teardown 后置操作) # test_a.pydef test_a():用例描述:test_aprint(123) 运行结果 最后感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 ​ 这些资料对于【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴上万个测试工程师们走过最艰难的路程希望也能帮助到你
http://www.w-s-a.com/news/919128/

相关文章:

  • 做网站可以申请个体户么网站的定位分析
  • jsp做的零食网站下载wordpress侧边栏折叠
  • 帝国网站单页做301南京旅游网站建设公司
  • 网站sem优化怎么做网站建设推广安徽
  • 比较好的室内设计网站潍坊网络科技
  • 南宁网站建设公设计联盟网站
  • 多个图表统计的网站怎么做百度推广费2800元每年都有吗
  • 连江县住房和城乡建设局网站企业类网站模版
  • 临沂seo整站优化厂家网站建设 大公司排名
  • 网站开发有哪些方式百度导航怎么下载
  • 网站认证免费视频直播网站建设方案
  • 瀑布流分享网站源代码下载网站构建的一般流程是什么
  • wordpress 4.9 多站wordpress邮箱解析
  • 微信网站开发企业汽车网站设计模板
  • 如何提升网站转化率遵义市公共资源交易平台
  • 网站目录管理模板企业解决方案部
  • 建设网站上申请劳务资质吗珠海哪个公司建设网站好
  • c2c商城网站建设在微信怎么开发公众号
  • 美的公司网站建设的目的做个网站要钱吗
  • 和县建设局网站孟州网站建设
  • 网站与规划设计思路竞价培训课程
  • 网站建设设计视频专业设计企业网站
  • 湖南省建设工程网站cerntos wordpress
  • 主机屋的免费空间怎么上传网站广告公司的经营范围有哪些
  • 门户网站建设公司案例门户建设是什么意思
  • 深圳seo专家东莞网站关键词优化排名
  • 套用别人产品图片做网站如何在阿里云自主建网站
  • 网站开发需要用哪些东西wordpress页面参数
  • 大连模板网站制作哪家好wordpress 安装不上
  • 宝塔搭建网站首页图片点击率如何提高