Python 如果在 Robot Framework 中用作自定义关键字,模块无法按预期工作

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)

returns

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