首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >:'OnDemand‘对象没有属性'calc’

:'OnDemand‘对象没有属性'calc’
EN

Stack Overflow用户
提问于 2014-06-25 10:24:49
回答 1查看 561关注 0票数 1

有些事情真的发生了,我几乎一天都无法下决心

示例如下:尝试一个简单的方法从一个类调用到另一个类来解决问题,因为我今天早上也经历了这个臭名昭著的问题.所以尝试了一种简单的方法.两类: HomePageAlone OnDemand

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

守则如下:

HomePageAlone

代码语言:javascript
复制
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

代码语言:javascript
复制
from sikuli import *

class OnDemand(object):

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


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

日志消息

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

错误:(main.homePage) test_E_Access

回溯(最近一次调用):文件"C:\DOCUME~1\Senthil.S\LOCALS~1\Temp\sikuli-6018543662740221054.py",第15行,在test_E_Access callMethod.calc(self) # Line#15 AttributeError中:'OnDemand‘对象没有属性'calc’

0.016s的Ran 1测试

失败(errors=1)

另一次尝试:我尝试使用下面的代码片段作为您的建议-它总是抛出AttributeError:'OnDemandPopular‘对象没有属性'calc’

导入OnDemandPopular ondemand = OnDemandPopular.OnDemandPopular() ondemand.calc()

请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-25 10:30:03

您应该从OnDemand模块导入OnDemand类;

代码语言:javascript
复制
from OnDemand import OnDemand

HomePageAlone

代码语言:javascript
复制
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)

OnDemand

代码语言:javascript
复制
class OnDemand(object):

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

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

输出为;

代码语言:javascript
复制
This is calling
test_E_Access (HomePageAlone.homePage) ... ok

Test
This is calling
----------------------------------------------------------------------

Ran 1 test in 0.000s

OK
Test
This is calling
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24406130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档