测试类执行报错: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
随机推荐
- Content Security Policy的学习理解
以下内容转载自 http://www.cnblogs.com/alisecurity/p/5924023.html 跨域脚本攻击 XSS 是最常见.危害最大的网页安全漏洞. 为了防止它们,要采取很多编 ...
- JAVA基础--JAVA 集合框架(泛型、file类)16
一.集合总结 集合:Collection体系.Map体系. Collection体系:单列集合的共性操作规则. List:列表,可以重复,有下标,拥有特有的迭代器ListIterator. Array ...
- Linux whereis 搜索命令位置
在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 文件搜索命令: whereis 基础的命令 命令名称:whereis 命令的所在路径:/usr ...
- 翻转链表中相邻的k个节点
示例: 输入:1->2->3->4->5 k=2 输出:2->1->4->3->5 k=3输出:3->2->1->4->5 Py ...
- layui icon样式1到7
1: 2: 3: 4: 5: 6: 7:
- Modulation of Lipid Metabolism by Celastrol (文献分享一组-赵倩倩)
文献名:Modulation of Lipid Metabolism by Celastrol (雷公藤红素对脂质代谢调节作用的研究) 期刊名:Journal of Proteome Research ...
- CAS单点登录之服务端部署
一.CAS服务端搭建 1.1 CAS支持Http登录配置 CAS默认是要https的链接才能登录的,不过学习的话是可以先去掉https限制,本博客介绍的是基于Cas4.2.7的,之前改过4.0的,详情 ...
- 受保护的封装 protected
补充内容:封装 私有化封装 private受保护的封装 protected公共的封装 public 注意:python目前不支持设定受保护的成员,但是开发者由约定的使用方式 受保护的封装:在成员名称前 ...
- C# 基础之类与结构体的区别
1.语法上的区别是: 定义类使用关键字class,定义结构体用关键字struct 2.结构体中不可对声明字段进行初始化,但类可以 3. 类:如果没有为类显示的定义一个构造函数,c#编译器会自动生成一个 ...
- CVE-2017-5638——S2-045
一. 漏洞简介 Apache Struts是美国阿帕奇(Apache)软件基金会负责维护的一个开源项目,是一套用于创建企业级Java Web 应用的开源MVC框架,主要提供两个版本框架产品: Stru ...