python 断言大全
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 断言大全的更多相关文章
- Python 资源大全中文版
Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列 ...
- [转载]Python 资源大全
原文链接:Python 资源大全 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex ...
- Python 库大全
作者:Lingfeng Ai链接:http://www.zhihu.com/question/24590883/answer/92420471来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...
- [转]Python 资源大全中文版
摘自:https://github.com/jobbole/awesome-python-cn 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesom ...
- python模块大全
python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...
- 【python】Python 资源大全中文版
申明:感谢原作者的整理与分享,本篇文章分享自:https://www.jianshu.com/p/9c6ae64a1bd7 GitHub 上有一个 Awesome - XXX 系列的资源整理,资源非常 ...
- Python 资源大全
我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列表,内容包括:Web框架.网络 ...
- 年薪20万Python工程师进阶(7):Python资源大全,让你相见恨晚的Python库
我是 环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环 ...
- Python资料大全
说明:以下文章为转载,有英文原文和中文整理翻译,对原作者和译者的工作表示极大感谢!!! 英文原文:https://github.com/vinta/awesome-python 中文译文:https: ...
随机推荐
- ubuntu 容器安装ping ifconfig ip命令
进入容器测试ifconfig ping 没有-------->>很尴尬 apt-get install net-tools ### ifconfig apt-get install ...
- django基础 -- 6. 多表操作
一.多表的创建 from django.db import models # Create your models here. class Author(models.Model): id = mod ...
- python --- 17. 面向对象成员
面向对象的成员 能写的所有成员 一.变量 1.实例变量 访问时 对象.变量 2.类变量 访问时 类名.变量 注意: 二.方法 1.实例方法 必须有一个参数(self) 调用时 ...
- matlab练习程序(k-means聚类)
聚类算法,不是分类算法. 分类算法是给一个数据,然后判断这个数据属于已分好的类中的具体哪一类. 聚类算法是给一大堆原始数据,然后通过算法将其中具有相似特征的数据聚为一类. 这里的k-means聚类,是 ...
- C语言goto语句的使用
不使用goto语句: 使用goto语句: 使用goto语句时需要注意以下原则:1) 不要过份地使用.比如图2中的60行就没有采用goto语句跳到程序的最后面,之所以这里不使用goto是为了阅读方便.因 ...
- 百度搜索引擎取真实地址-python代码
代码 def parseBaidu(keyword, pagenum): keywordsBaseURL = 'https://www.baidu.com/s?wd=' + str(quote(key ...
- 51nod 四级题 汇总
51Nod-1060-最复杂的数 #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; ...
- python学习打卡 day07 set集合,深浅拷贝以及部分知识点补充
本节的主要内容: 基础数据类型补充 set集合 深浅拷贝 主要内容: 一.基础数据类型补充 字符串: li = ["李嘉诚", "麻花藤", "⻩海峰 ...
- Java volatile 有什么作用
在由Java语言编写的程序中.有时候为了提高程序的执行效率,编译器会自己主动对其进行优化,把经常被訪问的变量缓存起来,程序在读取这个变量的时候有可能会直接从缓存(比如寄存器)中来读取这个值.而不会去内 ...
- R语言可视化学习笔记之添加p-value和显著性标记--转载
https://www.jianshu.com/p/b7274afff14f?from=timeline #先加载包 library(ggpubr) #加载数据集ToothGrowth data(&q ...