unittest 添加多个ddt数据驱动后,报错:
FAILED (errors=1)
Error
Traceback (most recent call last):
File "D:\Anaconda3\lib\unittest\case.py", line 60, in testPartExecutor
yield
File "D:\Anaconda3\lib\unittest\case.py", line 676, in run
self._callTestMethod(testMethod)
File "D:\Anaconda3\lib\unittest\case.py", line 633, in _callTestMethod
method()
File "D:\Anaconda3\lib\unittest\loader.py", line 34, in testFailure
raise self._exception
File "D:\Anaconda3\lib\unittest\loader.py", line 169, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: type object 'forTestDDT' has no attribute 'test_2'
百度解决方案如下:
原因:
运行的时候光标的位置放在 test_2方法里面了,加了ddt后,运行时要先识别装饰的类。若将光标放在某一个方法后面的话,测试用例只会执行当前的方法,ddt识别不到类,就会报错。将光标放到外面,则运行通过,或者加main方法,再运行,也不会报错
参考自:https://blog.csdn.net/weixin_42976139/article/details/100672375