确实发生了一些事情,我几乎一天都无法解决
示例如下:尝试从一个类到另一个类的简单方法调用来找出问题,因为我今天早上也遇到了臭名昭著的问题......所以尝试了一个简单的方法调用检查......
二类:
主页单独
一经请求
HomePageAlone - 在 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)
一经请求
from sikuli import *
class OnDemand(object):
def setUp(self):
print("setup")
def calc(self):
print ("This is calling")
日志消息
==================================================== =====================
错误:test_E_Access ( 主 .homePage)
回溯(最近一次通话最后):
文件“C:\DOCUME~1\Senthil.S\LOCALS~1\Temp\sikuli-6018543662740221054.py”,第 15 行,在 test_E_Access
callMethod.calc(self) # Line#15
AttributeError: 'OnDemand' 对象没有属性 'calc'
在 0.016 秒内运行 1 次测试
失败(错误=1)
另一个尝试:我尝试按照您的建议使用以下代码段 - 它总是抛出 AttributeError: 'OnDemandPopular' object has no attribute 'calc'
导入 OnDemandPopular
ondemand = OnDemandPopular.OnDemandPopular()
ondemand.calc()
请帮忙
最佳答案
您应该导入 按需 来自 的类(class)按需 模块;
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")
输出是;
This is calling
test_E_Access (HomePageAlone.homePage) ... ok
Test
This is calling
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Test
This is calling
关于Python - 属性错误 : 'OnDemand' object has no attribute 'calc' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24406130/