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用法解析的更多相关文章

  1. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  2. dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'

    有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...

  3. 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'

    在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...

  4. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

  5. python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'

    python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...

  6. 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”

    报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...

  7. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

  8. python报错“AttributeError: 'set' object has no attribute 'items'“

    作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...

  9. [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'

    原因:openpyxl版本低,需升级 pip install --upgrade openpyxl

随机推荐

  1. Junit使用注意点

    注意点 1. 使用了@BeforeClass后@Ignore将会失效

  2. 使用you-get下载网页小视频(实际上你可以下载任意你想要的web网页中的内容)

    1. 什么是you-get? You-Get是一个小型的命令行实用程序,用于从Web下载媒体内容(视频,音频,图像),如果没有其他方便的方法可以尝试使用you-get. 2.安装you-get 打开命 ...

  3. 洛谷P3338 [ZJOI2014]力(FFT)

    传送门 题目要求$$E_i=\frac{F_i}{q_i}=\sum_{j=1}^{i-1}\frac{q_j}{(i-j)^2}-\sum_{j=i+1}^n\frac{q_j}{(j-i)^2}$ ...

  4. IT兄弟连 JavaWeb教程 Servlet会话跟踪 Session常用方法

    ●  public Object getAttribute(String name) 该方法返回在该session会话中具有指定名称的对象,如果没有指定名称的对象,则返回null. ●  public ...

  5. Aufree/trip-to-iOS

    https://github.com/Aufree/trip-to-iOS?utm_source=next.36kr.com  

  6. C++中各种简写及全称的库

    ATL(Active TEmplate Library)活动模板库 RPC(Remote Procedure Call Protocol)远程过程调用协议 DCE(Distributed Comput ...

  7. Log4j2 - Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFileAppender for element RollingFile

    问题与分析 在使用Log4j2时,虽然可以正确读取配置文件并生成log文件,但偶然发现控制台打印了异常信息如下: 2018-12-31 17:28:14,282 Log4j2-TF-19-Config ...

  8. VC 中TEXT、_T、L的区别

    http://i.cnblogs.com/EditPosts.aspx?opt=1 对于从VC++6.0转到VS2005编译环境中的程序员.往往会碰到字符集之间的转换. VC6.0采用的是ANSI字符 ...

  9. java对mongodb数据库的简单操作

    准备工作: 下载好mongodriver.jar包(https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb ...

  10. laravel配合swoole使用总结

    最近对接硬件做了两个项目,用到了swoole 第一个是门禁系统,需要远程开门.离线报警.定时开门.离线刷卡等功能 1.远程开门: 目前用cli创建个临时客户端连接服务端发送命令,服务端处理完成后客户端 ...