python not is函数_Python unittest assertIsNotNone()用法及代码示例
assertIsNotNonePython中的()是单元测试库函数,用于单元测试中以检查输入值是否为None。此函数将使用两个参数作为输入,并根据断言条件返回布尔值。如果输入值不等于无assertIsNotNone()将返回true,否则返回false。
用法: assertIsNotNone(testValue, message)
参数: assertIsNotNone()接受以下列出的两个参数并作解释:
testValue:将测试变量作为输入值以检查是否与None相等
message:作为测试消息失败时显示的消息的字符串语句。
下面列出了两个不同的示例,它们说明了给定assert函数的正面和负面测试案例:
示例1:否定测试用例
Python3
# unit test case
import unittest
class TestMethods(unittest.TestCase):
# test function
def test_negative(self):
firstValue = None
# error message in case if test case got failed
message = "Test value is none."
# assertIsNotNone() to check that if input value is not none
self.assertIsNotNone(firstValue, message)
if __name__ == '__main__':
unittest.main()
输出:
F
======================================================================
FAIL:test_negative (__main__.TestMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "p1.py", line 11, in test_negative
self.assertIsNotNone(firstValue, message)
AssertionError:unexpectedly None:Test value is none.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
示例2:正测试用例
Python3
# unit test case
import unittest
class TestMethods(unittest.TestCase):
# test function
def test_positive(self):
firstValue = "geeks"
# error message in case if test case got failed
message = "Test value is none."
# assertIsNotNone() to check that if input value is not none
self.assertIsNotNone(firstValue, message)
if __name__ == '__main__':
unittest.main()
输出:
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
参考:https://docs.python.org/3/library/unittest.html
python not is函数_Python unittest assertIsNotNone()用法及代码示例相关推荐
- python中squeeze函数_Python numpy.squeeze()用法及代码示例
当我们要从数组形状中删除一维条目时,将使用numpy.squeeze()函数. 用法: numpy.squeeze(arr, axis=None ) 参数: arr :[数组]输入数组. axis : ...
- python中argmin函数_Python numpy.argmin()用法及代码示例
numpy.argmin(array,axis = None,out = None):返回特定轴上数组min元素的索引. 参数: array:Input array to work on axis : ...
- python cos函数_Python Tensorflow cos()用法及代码示例
Tensorflow是Google开发的开源机器学习库.它的应用之一是开发深度神经网络. 模块tensorflow.math为许多基本的数学运算提供支持.功能tf.cos()[别名tf.math.co ...
- python中argmin函数_python中argmin函数_Python numpy.argmin()用法及代码示例
numpy.argmin(array,axis = None,out = None):返回特定轴上数组min元素的索引. 参数: array:Input array to work on axis : ...
- python的datetime举例_Python datetime.timedelta()用法及代码示例
Python timedelta()函数存在于datetime库中,该函数通常用于计算日期差,也可以用于Python中的日期操作.这是执行日期操作的最简单方法之一. 用法: datetime.time ...
- python json dumps 自定义_Python json.dumps()用法及代码示例
JSON的完整形式是JavaScript Object Notation.这意味着将使用编程语言的文本组成的脚本(可执行)文件用于存储和传输数据. Python通过名为内置的软件包支持JSONjson ...
- python的mag模块_Python Decimal max_mag()用法及代码示例
Decimal#max_mag():max_mag()是一个Decimal类方法,该方法比较两个Decimal值并返回两个最大值(忽略它们的符号). 用法: Decimal.max_mag() 参数: ...
- python的mag模块_Python Decimal min_mag()用法及代码示例
Decimal#min_mag():min_mag()是一个Decimal类方法,它比较两个Decimal值并返回两个最小值,而忽略它们的符号. 用法: Decimal.min_mag() 参数: D ...
- python实现关联算法_python实现关联规则算法Apriori代码示例
本篇文章小编给大家分享一下python实现关联规则算法Apriori代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 首先导入包含apriori ...
最新文章
- 超简单的react和typescript和引入scss项目搭建流程
- 两次杀人,自动驾驶技术之恶
- 谈谈“个人电子信息”的保护
- STM32 CJSON解析说明
- 使用脚本进行 SAP Spartacus 安装工作
- c语言结构体单元测试,C语言结构体单元练习.doc
- 鲲鹏服务器php性能,对鲲鹏服务器的内存进行性能优化后的前后数据对比
- CentOS依赖包查找工具(https://centos.pkgs.org)
- mac安装ElasticSearch
- era5数据内容说明_接口测试:A04_HttpRunner通用_02_提取数据_01_extract关键字
- android tv背景图片,android中shape绘制背景图片
- ftp 上传下载整个目录
- 小牛uqi几个版本区别_川崎ZX25R便宜版本长这样?
- Java入门 - 循环结构基础
- 如何删除Word中的边框线
- php阴阳万年历转换的接口,阴历阳历转换(阴阳转换万年历查询表)
- 淘宝技术四面,本以为三面过了就完了,没想到还有个交叉面试。
- swing hacks_这些firefox hacks和扩展程序增强了您的隐私
- OpenEmbedded Yocto BitBake Poky以及之间关系
- 如何画好设计素描?美术加推荐尝试这些方法~
热门文章
- 成长没你想的那么急切
- 【第51题】常用的数学工具类8-七星彩号码生成器
- 7 在UML中,( )展现了运行时处理结点以及其中构件(制品)的配置,给出了体系结构的静态视图
- 2019年最新Android API对应版本号
- 入门机器学习的必备Python库
- csp虚拟专用服务器,CSP应用服务端开发快速入门手册.doc
- linux 远程存储服务器,两台linux服务器远程备份
- arcgis fishnet 单位_【转】ArcGIS生成规则网格(Fishnet)
- Vue - 下载打印功能,将页面下载打印为 pdf 格式文件(vue-print-nb)
- mysql左连接—left join