gpt4 book ai didi

Python 属性错误 : Object has no attribute in Unittest

转载 作者:太空宇宙 更新时间:2023-11-04 00:10:07 24 4
gpt4 key购买 nike

我有 2 个脚本,第一个是 All_Methods,另一个是 All_Testcases,因为我使用的是单元测试框架,所以我们开始吧。

All_Methods 就像:

class All_Services():
def abc(self):
x =1

def bca(self):
print "My Name is Taimoor"
self.abc()

def cba(self):
self.bca()

在另一个脚本 All_TestCases 上是这样的:

from All_Methods import All_Services as service

class All_TestCases(unittest.TestCase):
def test_1_running_method(self)
service.cba(self)

异常显示是:

AttributeError: 'All_TestCases' object has no attribute 'bca'

请有人告诉我,我在这里缺少什么?谢谢。

最佳答案

当您将 self 传递给您在类上调用的方法时,您并没有以通常的方式使用类。常见的是在类的实例上调用方法并隐式获取 self 参数。

当您调用 Method.running_query_Athena(self) 时,self 是 All_TestCases 的一个实例,它没有 connecting_Athena 方法。

您的意思是 All_TestCases 派生自 All_Methods 吗?

为什么 All_Methods 根本就是一个类?

关于Python 属性错误 : Object has no attribute in Unittest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52815621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com