Chinaunix首页 | 论坛 | 博客
  • 博客访问: 588089
  • 博文数量: 80
  • 博客积分: 3315
  • 博客等级: 中校
  • 技术积分: 697
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-27 12:46
文章分类

全部博文(80)

文章存档

2014年(3)

2013年(3)

2012年(5)

2011年(19)

2010年(50)

我的朋友

分类: Python/Ruby

2012-08-16 16:22:16

问题描述
我有一个python 文件 megamon_connection.py, 这个文件里面定义了一个类,如下
    class megamon_connection:
        def connect_to_megamon(self, host, port, timeout, username, password): 
            oldcurrent = self._current 
            try: 
                self._current = TelnetConnection(host, port, self._prompt[:], timeout, "CR") 
                self._current.set_loglevel(self._loglevel) 
                self._current.un = username 
                self._current.pw = password 
                result = self._login(username, password) 
                if result: 
                    found = re.search(r"<\s*$",result) 
                    if found: print "normal megamon via telnet" 
            except: 
                 self._current = oldcurrent raise
我在类外面定义了同名调用函数
def connect_to_megamon(host, port=23, timeout="30sec", user="SYSTEM", passwd="SYSTEM", msg=None):
    """This keyword opens a connection to a megamon system and logs in, now support telnet mode.

    | Input Paramaters | Man. | Description |
    | host    |  Yes  | Identifies to host |
    | port    |  No   | Allows to change the default telnet port |
    | timeout |  No   | Timeout for commands issued on this connection. Default is 120 sec |
    | user    | No    | Authentication information |
    | passwd  | No    | Authentication information |
    | msg     |  No   |   |

    Example
    | Open Test | Connect To megamon | 10.69.248.247 |
    """
    try:
        conn = megamon_connection()
        current = conn.connect_to_megamon(host, port, timeout, user, passwd)
        
    except Exception, e:
        megamon_error._raise_critical_exceptions(e)
        if msg and msg.lower() != 'none':
            raise AssertionError(msg)
        else:
            raise  
    global current_conn
    current_conn = conn  
    return current

我在robot写了调用的case(已经在case中import 这个python文件)
Connect To Megamon ${HOST}

但是一直报错
Keyword 'megamon_connection.Connect To Megamon' expected 5 arguments, got 1.
这个问题查了半天,一直搞不明白,最后终于发现问题是,类名和文件名一样,直接调用到类里面的函数定义去了,没有调到外面的调用函数,所以又四个参数没有使用默认值,把类名或改文件名即可。


阅读(2473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~