Python-AttributeError:';OnDemand';对象没有属性';计算';
有些事情真的发生了,我几乎一天都无法解决 下面的例子是:尝试一个简单的方法从一个类调用到另一个类来解决这个问题,因为我今天早上也遇到了这个臭名昭著的问题。。。所以我尝试了一个简单的方法调用checks。。。 两类: 主页 OnDemand HomePageOnline-定义了一个测试“def test_E_Access(self):”调用OnDemand中的方法,我得到了以下错误 代码如下: 主页 OnDemandPython-AttributeError:';OnDemand';对象没有属性';计算';,python,class,error-handling,Python,Class,Error Handling,有些事情真的发生了,我几乎一天都无法解决 下面的例子是:尝试一个简单的方法从一个类调用到另一个类来解决这个问题,因为我今天早上也遇到了这个臭名昭著的问题。。。所以我尝试了一个简单的方法调用checks。。。 两类: 主页 OnDemand HomePageOnline-定义了一个测试“def test_E_Access(self):”调用OnDemand中的方法,我得到了以下错误 代码如下: 主页 OnDemand 日志消息 ==================================
日志消息 ====================================================================== 错误:测试访问(main.homePage) 回溯(最近一次呼叫最后一次): 测试访问中的第15行文件“C:\DOCUME~1\Senthil.S\LOCALS~1\Temp\sikuli-601854366274021054.py” callMethod.calc(自身)#行#15 AttributeError:“OnDemand”对象没有属性“calc”
在0.016s内运行1次测试 失败(错误=1) 另一次尝试:我尝试按照您的建议使用以下代码段-它总是抛出AttributeError:“OnDemandPopular”对象没有属性“calc” 进口和进口 ondemand=OnDemandPopular.OnDemandPopular() ondemand.calc() 请帮忙
您应该从OnDemand模块导入OnDemand类
from OnDemand import OnDemand
主页本身
import unittest
from OnDemand 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)
class OnDemand(object):
def setUp(self):
print("setup")
def calc(self):
print ("This is calling")
OnDemand
import unittest
from OnDemand 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)
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
模块和类之间有什么区别?类具有方法,并尝试通过导入和定义对象来访问类上的方法。你是说一个模块可以有多个类??请帮忙。本质上;模块包括类,你必须谷歌它!而且,如果答案是真的,你应该结束这个问题;单击以将此答案设置为您接受的答案。