Python AttributeError:“OnDemand”对象没有属性“calc”

2024-06-08 06:34:25 发布

您现在位置:Python中文网/ 问答频道 /正文

事情真的发生了,我几乎一天都无法解决

示例如下:尝试一个简单的方法从一个类调用到另一个类来解决问题,因为我今天早上也遇到了这个臭名昭著的问题。。。所以尝试了一个简单的方法调用checks。。。 两个等级: 仅主页 OnDemand公司

HomePageOnly—在OnDemand中定义了一个测试“def test_E_Access(self):”调用方法,我得到以下错误。在

代码如下:

仅主页

from sikuli import *
from OnDemand import *
import OnDemand

class homePage(unittest.TestCase):

 def setUp(self):
  print("Test")   


 def test_E_Access(self):
  callMethod = OnDemand()
  callMethod.calc() # Line#15


suite = unittest.TestSuite()
suite.addTest(homePage('test_E_Access'))
unittest.TextTestRunner(verbosity=2).run(suite)

OnDemand公司

^{pr2}$

日志消息

============================================================================

错误:测试访问权限(main.homePage)

回溯(最近一次呼叫): 文件“C:\DOCUME~1\sentil.S\LOCALS~1\Temp\sikuli-601854366274021054.py”,第15行,在test eu峈Access中 调用方法.calc(自我)第15行 AttributeError:“OnDemand”对象没有属性“calc”


在0.016s内运行了1次测试

失败(错误=1)

另一个尝试:我尝试按照您的建议使用下面的代码片段-它总是抛出AttributeError:“OnDemandPopular”对象没有属性“calc”

导入OnDemandPopular 按需=OnDemandPopular.OnDemandPopular.OnDemandPopular() 按需计算()

请帮忙



Tags: 方法testimportselfaccessdef错误公司
1条回答
网友
1楼 · 发布于 2024-06-08 06:34:25

OnDemand模块导入OnDemand

from OnDemand import OnDemand

仅主页

^{pr2}$

OnDemand

class OnDemand(object):

    def setUp(self):
        print("setup")

    def calc(self):
        print ("This is calling")

输出为:

This is calling
test_E_Access (HomePageAlone.homePage) ... ok

Test
This is calling
                                   

Ran 1 test in 0.000s

OK
Test
This is calling

相关问题 更多 >

    热门问题