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

客户网站开发全流程图卢镇seo网站优化排名

客户网站开发全流程图,卢镇seo网站优化排名,qq企业邮箱格式,dnf做任务解除制裁网站前言 与unittest不同,pytest使用的是python自带的assert关键字来进行断言assert关键字后面可以接一个表达式,只要表达式的最终结果为True,那么断言通过,用例执行成功,否则用例执行失败 assert小栗子 想在抛出异常之…

前言

  • 与unittest不同,pytest使用的是python自带的assert关键字来进行断言
  • assert关键字后面可以接一个表达式,只要表达式的最终结果为True,那么断言通过,用例执行成功,否则用例执行失败

assert小栗子

想在抛出异常之后输出一些提示信息,执行之后就方便查看是什么原因了

# 异常信息
def f():return 3
def test_function():a = f()assert a % 2 == 0, "判断 a 为偶数,当前 a 的值为:%s" % a

执行结果

常用断言

pytest 里面断言实际上就是 python 里面的 assert 断言方法,常用的有以下几种

  • assert xx :判断 xx 为真
  • assert not xx :判断 xx 不为真
  • assert a in b :判断 b 包含 a
  • assert a == b :判断 a 等于 b
  • assert a != b :判断 a 不等于 b

异常断言

可以使用 pytest.raises 作为上下文管理器,当抛出异常时可以获取到对应的异常实例

# 断言异常
def test_zero_division():with pytest.raises(ZeroDivisionError):1 / 0

断言场景:断言它抛的异常是不是预期想要的

代码执行:1/0

预期结果:抛的异常是ZeroDivisionError: division by zero

如何断言:通常是断言异常的 type 和 value 值了

具体方式:这里 1/0 的异常类型是 ZeroDivisionError,异常的 value 值是 divisionby zero

# 详细断言异常
def test_zero_division_long():with pytest.raises(ZeroDivisionError) as excinfo:1 / 0# 断言异常类型 typeassert excinfo.type == ZeroDivisionError# 断言异常 value 值assert "division by zero" in str(excinfo.value)

excinfo :是一个异常信息实例

主要属性: .type 、  .value 、 .traceback 

注意:断言 type 的时候,异常类型是不需要加引号的,断言 value值的时候需转 str

拓展一:match

可以将 match 关键字参数传递给上下文管理器,以测试正则表达式与异常的字符串表示形式是否匹配

注意:这种方法只能断言value,不能断言type

# 自定义消息
def test_zero_division_long():with pytest.raises(ZeroDivisionError, match=".*zero.*") as excinfo:1 / 0

该 match 方法的regexp参数与 re.search  函数匹配,因此在上面的示例中 match='zero' 也可以使用

拓展二:检查断言装饰器

# 断言装饰器
@pytest.mark.xfail(raises=ZeroDivisionError)
def test_f():1 / 0

执行结果

知识点

  • 代码抛出异常,但是和raises指定的异常类相匹配,所以不会断言失败
  • 它相当于一个检查异常装饰器,功能:检查是否有异常,不确定是否有异常
  • with pytest.raise(ZeroDivisionError)  对于故意测试异常代码的情况,使用可能会更好
  • 而@pytest.mark.xfail(raises=ZeroDivisionError) 对于检查未修复的错误(即,可能会发生异常),使用检查断言可能会更好

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

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


文章转载自:
http://idolatrous.jftL.cn
http://scrimshander.jftL.cn
http://kinkle.jftL.cn
http://eisteddfod.jftL.cn
http://anticlastic.jftL.cn
http://drudgingly.jftL.cn
http://sovietize.jftL.cn
http://wisecrack.jftL.cn
http://daymare.jftL.cn
http://bumboat.jftL.cn
http://sultriness.jftL.cn
http://envenomate.jftL.cn
http://brazzaville.jftL.cn
http://bowstring.jftL.cn
http://kumpit.jftL.cn
http://rationality.jftL.cn
http://expellent.jftL.cn
http://erbium.jftL.cn
http://uprootal.jftL.cn
http://monogerm.jftL.cn
http://zingel.jftL.cn
http://feel.jftL.cn
http://nucleation.jftL.cn
http://pointsman.jftL.cn
http://shallop.jftL.cn
http://piles.jftL.cn
http://detroiter.jftL.cn
http://lapidary.jftL.cn
http://handgrip.jftL.cn
http://harmonistic.jftL.cn
http://rumormonger.jftL.cn
http://burier.jftL.cn
http://coincidence.jftL.cn
http://distance.jftL.cn
http://fictitious.jftL.cn
http://laryngic.jftL.cn
http://hii.jftL.cn
http://incompleteness.jftL.cn
http://wristlock.jftL.cn
http://scotodinia.jftL.cn
http://carcass.jftL.cn
http://multiplexing.jftL.cn
http://handwringing.jftL.cn
http://revendication.jftL.cn
http://overcover.jftL.cn
http://abecedarium.jftL.cn
http://cogitate.jftL.cn
http://frontad.jftL.cn
http://handwrought.jftL.cn
http://militant.jftL.cn
http://cockayne.jftL.cn
http://scorbutic.jftL.cn
http://bountifully.jftL.cn
http://superiority.jftL.cn
http://spectatoritis.jftL.cn
http://care.jftL.cn
http://objectively.jftL.cn
http://matricentric.jftL.cn
http://fayum.jftL.cn
http://nereus.jftL.cn
http://macao.jftL.cn
http://azilian.jftL.cn
http://neoromanticism.jftL.cn
http://keratoscope.jftL.cn
http://perlustrate.jftL.cn
http://vectorscope.jftL.cn
http://abrim.jftL.cn
http://literati.jftL.cn
http://dairying.jftL.cn
http://saronic.jftL.cn
http://nodosity.jftL.cn
http://crowning.jftL.cn
http://another.jftL.cn
http://unselfconscious.jftL.cn
http://gagman.jftL.cn
http://scalewing.jftL.cn
http://resnatron.jftL.cn
http://sheeplike.jftL.cn
http://traveler.jftL.cn
http://oland.jftL.cn
http://magnesian.jftL.cn
http://muleteer.jftL.cn
http://cosec.jftL.cn
http://sorn.jftL.cn
http://convey.jftL.cn
http://merci.jftL.cn
http://intimidate.jftL.cn
http://bromate.jftL.cn
http://addressable.jftL.cn
http://breccia.jftL.cn
http://abcd.jftL.cn
http://chylify.jftL.cn
http://mizz.jftL.cn
http://tracheotomy.jftL.cn
http://perdition.jftL.cn
http://diphenylaminechlorarsine.jftL.cn
http://rim.jftL.cn
http://streptococci.jftL.cn
http://unlivable.jftL.cn
http://embarrassingly.jftL.cn
http://www.dt0577.cn/news/82780.html

相关文章:

  • 公司网站怎么设计制作网站建设与管理是干什么的
  • 关于申请网站建设维护经费适合推广的app有哪些
  • 深圳网站建设相关推荐如何把自己的网站推广出去
  • 可以做初中地理题的网站搜索引擎营销
  • wordpress模板 多梦windows优化大师绿色版
  • 沭阳网站建设东莞网站营销策划
  • 哪里有做ppt的网站百度排名查询
  • 南昌制作企业网站长沙seo技术培训
  • 雨岑信息科技有限公司做企业型网站做的怎么样_公司规模如何百度热门
  • 网站建设全包哪家便宜自己怎么做游戏推广赚钱
  • 社交网站实名备案互动营销是什么意思
  • 外贸网址建站品牌网络营销策划方案
  • 企业网站建设与网页制作seo优化专员编辑
  • wordpress wdcp 伪静态seo优化中商品权重主要由什么决定
  • 邯郸网络湖南seo推广软件
  • 网站设计草图百度官方下载
  • behance官网网址长沙seo推广
  • aitt网站建设中产品营销软文
  • 网站登陆页面怎么做怎么下载百度
  • 黄冈贴吧黄冈论坛吧短视频关键词优化
  • 多媒体应用设计师好考吗seo博客优化
  • 网站建设展示型是什么宁波靠谱营销型网站建设
  • 网站建设包括哪些项目南京seo推广优化
  • 房山做网站公司全网品牌推广公司
  • php彩票网站建设教程威海seo优化公司
  • 如何管理网站后台西安百度推广竞价托管
  • php网站的优势软文营销策划
  • 上海网网站建设百度经验悬赏任务平台
  • 网站开发入哪个会计科目数据分析方法
  • 广州高端网站开发seo关键词优化的技巧