ddt AttributeError: type object 'TestLogin' has no attribute 'test_login_1_failed_by_wrong_datas1'
错误信息如下:
Error
Traceback (most recent call last):
File "D:\python37\lib\unittest\case.py", line 59, in testPartExecutor
yield
File "D:\python37\lib\unittest\case.py", line 628, in run
testMethod()
File "D:\python37\lib\unittest\loader.py", line 34, in testFailure
raise self._exception
File "D:\python37\lib\unittest\loader.py", line 169, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: type object 'TestLogin' has no attribute 'test_login_1_failed_by_wrong_datas1'
Ran 1 test in 0.004s
FAILED (errors=1)
Process finished with exit code 1
Assertion failed
Assertion failed
Assertion failed
通过调查发现原因:
运行的时候光标的位置放在test_login_0_success方法里面,可以正常执行一条测试用例,后面2条用例加了ddt后,运行时要先识别装饰的类,将光标放在某一个方法后面的话,测试用例只会执行当前的方法,ddt识别不到类,就会报错。
将光标放到类的外面,则运行所有的测试用例,所有的测试用例都运行通过,或者加main方法,再运行,也不会报错。
其他可能原因:setUp或者tearDown 拼写错误也可能报此错误