如果我从控制台调用此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
但是如果我在这样的
机器人框架测试用例中使用此函数作为自定义关键字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 )。这是为什么?
答案 0 :(得分:1)
我花了一些时间才意识到在RF中传递给我的自定义关键字的参数
${d} = Get Nearest Date 1 1
实际上是字符串。传递数字变量可以解决这个问题:
${d} = Get Nearest Date ${1} ${1}