数据驱动ddt运行报错AttributeError: type object 'DataaTest' has no attribute 'test_add'

ddt运行报错AttributeError: type object 'DataaTest' has no attribute 'test_add'

数据驱动ddt运行报错AttributeError: type object 'DataaTest' has no attribute 'test_add'

源代码:

# !/usr/bin/python
# -*- coding:utf-8 -*-
# Author:Ethan
# @Time: 2019/1/4 18:05
import ddt,unittest
ata=[['[email protected]', '123456789', 'None', 'http://47.88.50.127:8061/home', 'None', '账号密码为真'],
        ['[email protected]', '123456789', 'None', 'http://47.88.50.127:8061/home', 'None', '账号密码为真']]
@ddt.ddt   #####数据驱动
class DataaTest(unittest.TestCase):

    def setUp(self):
        print("这是setup")

    def tearDown(self):
        print("这是teardown")

    @ddt.data(*data)
    @ddt.unpack   ###解包
    def test_add(self,username, password, error, url, account_massage, describe):
        print(username,password,error,url,account_massage,describe)

if __name__=='__main__':
    unittest.main()

 

 

原因:运行的时候光标的位置放在 test_login 方法里面了,加了ddt后,运行时要先识别装饰的类,将光标放在某一个方法后面的话,测试用例只会执行当前的方法,ddt识别不到类,就会报错,

将光标放到外面,则运行通过,或者加main方法,再运行,也不会报错

 

其他可能原因,setUp 或者 tearDown 拼写错误也可能报此错误

原文链接:https://www.cnblogs.com/kulankadamei/p/10166066.html