Python AttributeError:对象在单元测试中没有属性

Tai*_*oor 6 python methods class python-unittest

我有 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()
Run Code Online (Sandbox Code Playgroud)

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

from All_Methods import All_Services as service

    class All_TestCases(unittest.TestCase):
        def test_1_running_method(self)
            service.cba(self)
Run Code Online (Sandbox Code Playgroud)

异常显示是:

AttributeError: 'All_TestCases' object has no attribute 'bca'
Run Code Online (Sandbox Code Playgroud)

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

Mob*_*erg 2

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

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

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

为什么是All_Methods一个类呢?