如何检查Robot Framework中的变量类型?

Bak*_*Bug 3 robotframework

我正在使用 Robot Framework 来测试一个返回 int 的系统,该 int 表示系统在测试时遇到的错误数。但是,如果系统变得无响应,则返回将是 NoneType 并且我收到此错误: 'None' cannot be converted to an integer: TypeError: int() argument must be a string or a number, not 'NoneType'

我无法使用该Should Be True关键字,因为传递的响应将为 0。

有什么方法可以测试机器人中变量的类型吗?我的目标是做这样的事情:

Should Not Be NoneType    ${error_count}    msg=System is not responding after test.
Should Be Equal As Integers    ${error_count}    ${0}    msg=System generated ${error_count} errors during test.
Run Code Online (Sandbox Code Playgroud)

ILo*_*oon 5

要检查是否 ${error_count}为None,您可以执行以下操作:

Should Be True    ${error_count} is not ${None}    msg=Returned None
Run Code Online (Sandbox Code Playgroud)

只要前面的语句通过,您的测试就可以继续打印结果,如下所示:

Log to Console    System generated ${error_count} errors during test
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用关键字将所有内容合并到一行中Run Keyword Unless:

Run Keyword Unless    ${error_count} is ${None}    Log to Console    System generated ${error_count} errors during test    
Run Code Online (Sandbox Code Playgroud)