[英][robotframework]Why Create a empty element to a list can treat as True, but not applicable to a empty variable
Create a empty element to a list, and return True value with "Should Be True" key word.为列表创建一个空元素,并使用“应该为真”关键字返回 True 值。 but not suiteable for create a empty variable.Why is that?
但不适合创建空变量。这是为什么? code:
代码:
${list1} Create List ${EMPTY}
${list2} Set Variable ${EMPTY}
Should Be True ${list1} Create empty list
Should Be True ${list2} Set empty variable
Log:日志:
20211225 14:24:58.913: INFO: ${list1} = [''] 20211225 14:24:58.913: 信息: ${list1} = ['']
20211225 14:24:58.916: TRACE: Arguments: [ '' ] 20211225 14:24:58.916:跟踪:Arguments:['']
20211225 14:24:58.916: TRACE: Return: '' 20211225 14:24:58.916:跟踪:返回:''
20211225 14:24:58.917: INFO: ${list2} = 20211225 14:24:58.917:信息:${list2} =
20211225 14:24:58.918: TRACE: Arguments: [ [''] | 20211225 14:24:58.918:跟踪:Arguments:[[''] | 'Create empty list' ]
'创建空列表' ]
20211225 14:24:58.918: TRACE: Return: None 20211225 14:24:58.918:跟踪:返回:无
20211225 14:24:58.919: TRACE: Arguments: [ '' | 20211225 14:24:58.919:跟踪:Arguments:[''| 'Set empty variable' ]
'设置空变量']
20211225 14:24:58.920: FAIL: Evaluating expression '' failed: ValueError: Expression cannot be empty. 20211225 14:24:58.920:失败:评估表达式''失败:ValueError:表达式不能为空。
It is a bit counter-intuitive because ${list1} Create List ${EMPTY}
is not creating an empty list, but a list with an empty element inside, eg ['']
, while ${list2} Set Variable ${EMPTY}
will create an empty variable, eg ''
.这有点违反直觉,因为
${list1} Create List ${EMPTY}
不是创建一个空列表,而是一个内部有一个空元素的列表,例如['']
,而${list2} Set Variable ${EMPTY}
将创建一个空变量,例如''
。 This is why Should Be True
passes on the list (list is not empty) but fails on the variable (variable is empty).这就是为什么
Should Be True
通过列表(列表不为空)但在变量上失败(变量为空)。
Below code exemplifies these cases:下面的代码举例说明了这些情况:
# empty_list == []
${empty_list} = Create List
log to console ${empty_list}
should be empty ${empty_list}
# empty_list_1 == ['']
${empty_list_1} = Create List ${EMPTY}
log to console ${empty_list_1}
should not be empty ${empty_list_1}
# empty_var == '' (empty string with length 0)
${empty_var} = Set Variable
log to console ${empty_var}
should be empty ${empty_var}
# empty_var_1 == '' (empty string with length 0)
${empty_var_1} = Set Variable ${EMPTY}
log to console ${empty_var_1}
should be empty ${empty_var_1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.