测试类执行报错:AttributeError: 'Testlei' object has no attribute 'test_cases' 和data,unpack用法解析
a=[{"}]
import unittest
from ddt import ddt,data,unpack
@ddt
class Testlei(unittest.TestCase):
def setUp(self):
print("开始")
# ([{"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"}])
@data(*a)#({"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"})
def test_cases(self,d):
print(d["预期"])
def tearDown(self):
print("结束")
if __name__ == '__main__':
Testlei().test_cases()
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe E:/yzm_pj/test_a.py
Traceback (most recent call last):
File "E:/yzm_pj/test_a.py", line 55, in <module>
Testlei().test_cases()
AttributeError: 'Testlei' object has no attribute 'test_cases'
原因如下,右键执行的时候只显示模块,没有uninttest

解决方法:
方法一:用unitest.main()执行
a=[{"}]
import unittest
from ddt import ddt,data,unpack
@ddt
class Testlei(unittest.TestCase):
def setUp(self):
print("开始")
# ([{"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"}])
@data(*a)#({"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"})
def test_cases(self,d):
print(d["预期"])
def tearDown(self):
print("结束")
if __name__ == '__main__':
unittest.main()
方法二:点击pycharm菜单栏的run按钮

切换unitest

执行成功

unpack
a=[{"}]
import unittest
from ddt import ddt,data,unpack
@ddt
class Testlei(unittest.TestCase):
def setUp(self):
print("开始")
# ([{"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"}])
@data(*a)#({"步骤":"123",'结果':"123","预期":"3"},{"步骤":"1",'结果':"1","预期":"1"})
@unpack# 再将{"步骤":"123",'结果':"123","预期":"3"}和{"步骤":"1",'结果':"1","预期":"1"}拆分
# 以逗号作为拆分点,可以拆分多少个,就用几个参数接收。
def test_cases(self,aa,bb,cc):#aa,bb,cc接收必须是key名
fact=3#给定一个实际结果
try:
self.assertEqual(int(cc),fact)
print("比对成功{}与{}相等".format(int(cc),fact))
except Exception as e:
print("比对失败{}与{}不相等".format(int(cc),fact))
raise e
def tearDown(self):
print("结束")
if __name__ == '__main__':
Testlei().test_cases()
运行结果

测试类执行报错:AttributeError: 'Testlei' object has no attribute 'test_cases' 和data,unpack用法解析的更多相关文章
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- python报错“AttributeError: 'set' object has no attribute 'items'“
作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
随机推荐
- 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解
https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p ...
- Mac Apache
参考文章1 当前系统版本:Mac OS 10.11.6 一.使用 homebrew 安装 apache 停止系统自带的 apache 服务 $ sudo apachectl stop 卸载系统自带的 ...
- Cannot set headers after they are sent to the client
D:\le\node_modules\mysql\lib\protocol\Parser.js: throw err; // Rethrow non-MySQL errors ^ Error [ERR ...
- zepto+mui开发中的tap事件重复执行
zepto.js和mui一起使用的时候,因为都有tap事件绑定tab事件后会多次触发还会报错,这时不引用zepto中的touch.js就可以了,只用mui的tap相关事件. $(function () ...
- Node.js 关于module的一些认知
module是一个对象,在Node环境中运行js脚本,module会自动添加,并且系统会将函数封装到另一个函数中 例如: var module = { id: '.', exports: {} }; ...
- IT兄弟连 JavaWeb教程 JSP内置对象2
application对象 application对象用于保存所有应用程序中的公有数据.它在服务器启动时自动创建,在服务器关闭时销毁,当application对象没有被销毁时,所有用户都可以共享app ...
- windows 自定义批处理BAT/CMD启动Redis等软件
需求:每次开机都需要启动Redis.QQ.IDEA等等好几个软件,手动点击比较无趣.浪费劳动力,所以通过自定义bat文件,进行批量启动. 唯独启动到Redis时出现问题,下面是在bat里运行的路径: ...
- linux ping
ping [ -d] [ -D ] [ -n ] [ -q ] [ -r] [ -v] [ -R ] [ -a addr_family ] [ -c Count ] [ -w timeout ...
- Android近场通信---NFC基础(四)(转)
转自http://blog.csdn.net/think_soft/article/details/8184539 从Intent中获取信息 如果因为NFC的Intent而启动一个Activity,那 ...
- Date类学习一