参考链接:https://blog.csdn.net/qq1124794084/article/details/51668672

1. 小数位模糊等于

自动化脚本最重要的是断言,正确设置断言以后才能帮助我们判断测试用例执行结果。

在小同事的帮助下,整理了一份比较详细的断言方法。

一、先说说unittest常用的断言吧

常用的就以下几个,网上一搜一大堆。python版本2.7以上都可以调用了。

断言语法 解释
(默认为7),如果在place位以内不同则断言失败。

assertDictContainsSubset(expected, actual[, msg])

个多行字符串是相等的

assertNotAlmostEqual(first, second[, ...])

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

assertNotAlmostEquals(first, second[, ...])

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

assertNotEqual(first, second[, msg])

Fail if the two objects are equal as determined by the ‘==’

assertNotEquals(first, second[, msg])

Fail if the two objects are equal as determined by the ‘==’

assertNotIn(member, container[, msg])

Just like self.assertTrue(a not in b), but with a nicer default message.

assertNotIsInstance(obj, cls[, msg])

Included for symmetry with assertIsInstance.

assertNotRegexpMatches(text, unexpected_regexp)

如果文本匹配正则表达式,将失败。

assertRaises(excClass[, callableObj])

除非excclass类抛出异常失败

assertRaisesRegexp(expected_exception, ...)

认为在引发异常的情况下消息匹配一个正则表达式。

assertRegexpMatches(text, expected_regexp[, msg])

测试失败,除非文本匹配正则表达式。

assertSequenceEqual(seq1, seq2[, msg, seq_type])

有序序列的相等断言 (like lists and tuples).

assertSetEqual(set1, set2[, msg])

A set-specific equality assertion.

assertTrue(expr[, msg])

Check that the expression is true.

assertTupleEqual(tuple1, tuple2[, msg])

A tuple-specific equality assertion.

assert_(expr[, msg])

Check that the expression is true.


三、在unittest包里面看到的比较全的断言

python 断言大全的更多相关文章

  1. Python 资源大全中文版

    Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列 ...

  2. [转载]Python 资源大全

    原文链接:Python 资源大全 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex  ...

  3. Python 库大全

    作者:Lingfeng Ai链接:http://www.zhihu.com/question/24590883/answer/92420471来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...

  4. [转]Python 资源大全中文版

    摘自:https://github.com/jobbole/awesome-python-cn 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesom ...

  5. python模块大全

    python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...

  6. 【python】Python 资源大全中文版

    申明:感谢原作者的整理与分享,本篇文章分享自:https://www.jianshu.com/p/9c6ae64a1bd7 GitHub 上有一个 Awesome - XXX 系列的资源整理,资源非常 ...

  7. Python 资源大全

    我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列表,内容包括:Web框架.网络 ...

  8. 年薪20万Python工程师进阶(7):Python资源大全,让你相见恨晚的Python库

    我是 环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环 ...

  9. Python资料大全

    说明:以下文章为转载,有英文原文和中文整理翻译,对原作者和译者的工作表示极大感谢!!! 英文原文:https://github.com/vinta/awesome-python 中文译文:https: ...

随机推荐

  1. [J2EE]struts+ejb笔记

    DispatchAtion: - org.apache.struts.actions.DispatchAction 这个类是个抽象类,但实现父类Action的execute方法,在项目中重写这个类可以 ...

  2. Magnum Kubernetes源码分析(二)

    Kubernetes Master Stack kubernetes master的stack的resources主要分为三个部分. master wait handle wait handle主要用 ...

  3. fedora23安装搜狗輸入法?

    1, 安裝方法, 是通過下載 repo文件, 添加repo文件, 然後通過dnf啦安裝的. repo文件地址是: fedora 的中文社區: https://www.fdzh.org/ fdzh: 就 ...

  4. 如何清除浮动塌陷? float:left 塌陷

    参考文章: http://www.jb51.net/css/502268.html 原文链接:http://www.jianshu.com/p/a0500b54da13 只要给li的宽度, 规定得小一 ...

  5. (zhuan) Speech and Natural Language Processing

    Speech and Natural Language Processing obtain from this link: https://github.com/edobashira/speech-l ...

  6. [quartz] - Cron表达式举例

    Quartz是一个任务调度框架.比如你遇到这样的问题 想每月25号,信用卡自动还款 想每年2月14日自己给当年暗恋女神发一封匿名贺卡 想每隔1小时,备份一下自己的SpringCloud学习笔记到云盘 ...

  7. 比原链设计思考: 扩展性UTXO模型

    用户模型是比原链在最初就需要确定的重要数据结构, 团队的选择还是聚焦在两种典型的模型系统中,Account模型和UTXO模型,和其他大多数区块链设计一样, 选择了模型就决定了协议层的重要实现,两种模型 ...

  8. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ppcloud-common: Compilation failure

    本文为博主原创,未经允许不得转载: [INFO] Finished at: 2018-09-19T20:26:05+08:00[INFO] ------------------------------ ...

  9. Spring Cloud各组件超时总结

    Ribbon的超时 全局设置: ribbon: ReadTimeout: 60000 ConnectTimeout: 60000 1 2 3 局部设置: service-id: ribbon: Rea ...

  10. 《算法竞赛入门经典》刘汝佳 C语言部分(前四章)“注解与习题” 之思索 -<1>

    此书我购于去年的十一月份,也是经前人推荐购买的一本比较有用的书籍,在寒假自学此书,其简洁清晰高效的示例代码令我印象深刻,于是我打算把这本书的前四章后面的注解与习题(未给出标准解答)认真的去思索和研究, ...