繁体   English   中英

如果在Robot Framework中用作自定义关键字,Python模块将无法正常工作

[英]Python module does not work as expected, if used as custom keyword in Robot Framework

如果我从控制台调用此pathon函数,则将按预期计算日期:

def get_nearest_date(day, month):
    """Gets nearest date in the future for provided day and month."""
    today = date.today()
    res = ""
    if (today.month < month):
        res = str(day) + "." + str(month) + "." + str(today.year)
    elif ((today.month == month) & (today.day < day)):
        res = str(day) + "." + str(month) + "." + str(today.year)
    else: 
        res = str(day) + "." + str(month) + "." + str((today.year + 1))
    return res

例如:

print   get_nearest_date(1, 1)
print   get_nearest_date(1, 12)

回报

1.1.2016
1.12.2015

但是,如果我在像这样的Robot Framework测试用例中将此功能用作自定义关键字,

Bla    
    ${d} =    Get Nearest Date    1   1
    Log To Console  ${d}
    ${d} =    Get Nearest Date    1   12
    Log To Console  ${d}

它打印

Bla                                                                   
1.1.2015
1.12.2015

这是错误的(第一次约会应该是2016年 )。 为什么是这样?

我花了一些时间才意识到,在RF中,参数传递给了我的自定义关键字

${d} =    Get Nearest Date    1   1

实际上是字符串。 传递数字变量可以解决此问题:

${d} =    Get Nearest Date     ${1}    ${1}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM