python unittest 继承时出现 object has no attribute '_testMethodDoc'
2017-09-10 15:50
966 查看
之前没有注意过, 这次出现了, google了一下, 找到原因, 这里作为记录:
class AppTest(unittest.TestCase):
def __init__(self, arg1, arg2):
pass
从unittest.TestCase继承后随手定义了__init__, 其实当时里面啥也没写, 当框架写完, 运行时出现错误:
AttributeError: 'AppTest' object has no attribute '_testMethodDoc'
原因如下:
你的__init__ 不小心override掉了unittest.TestCase的对应函数, 导致错误. 所以要记得在你的init中再调用父类的init.
class AppTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
答案地址: https://stackoverflow.com/questions/7562775/deriving-a-class-from-testcase-throws-two-errors
class AppTest(unittest.TestCase):
def __init__(self, arg1, arg2):
pass
从unittest.TestCase继承后随手定义了__init__, 其实当时里面啥也没写, 当框架写完, 运行时出现错误:
AttributeError: 'AppTest' object has no attribute '_testMethodDoc'
原因如下:
你的__init__ 不小心override掉了unittest.TestCase的对应函数, 导致错误. 所以要记得在你的init中再调用父类的init.
class AppTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
答案地址: https://stackoverflow.com/questions/7562775/deriving-a-class-from-testcase-throws-two-errors
相关文章推荐
- Python连接字符串,join出现问题:python 'list' object has no attribute
- 'module' object has no attribute 在python开发中出现的原因
- Python报错——错误“AttributeError:'builtin_function_or_method' object has no attribute 'sleep'”
- python :TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- unittest 'module' object has no attribute 'TestCase'--自己坑自己
- python 编译错误TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- 使用sae-python-dev本地运行web.py项目出现module object has no attribute InteractiveInterpreter
- python 中出现的AttributeError: 'module' object has no attribute '_handlerList'
- 关于python里运行出现'module' object has no attribute 'xxxx'等问题解决方法
- 【转载】C#调用python文件时出现'module' object has no attribute '_getframe'
- Python:AttributeError: 'function' object has no attribute '_doc_'
- Python3.4 pandas 在IDLE出现AttributeError: 'NoneType' object has no attribute 'fileno'
- python PIL bug: 'NoneType' object has no attribute 'bands' (解决)
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- pyinstaller安装出现'NoneType' object has no attribute 'rfind'问题解决
- 部署爬虫到scrapy cloud上出现'_sre.SRE_Match' object has no attribute '__getitem__'的错误
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'