Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在robot关键字中实现增量数值变量_Python_Robotframework - Fatal编程技术网

Python 在robot关键字中实现增量数值变量

Python 在robot关键字中实现增量数值变量,python,robotframework,Python,Robotframework,我想创建一个robot关键字,每次调用它都会增加一个数字,但我无法让它工作 我尝试了几种实现增量的方法,有些只是给出了错误。下面的代码将通过,但请将变量保持在其原始值 *** Variables *** ${counter}= ${1} *** Keywords *** my keyword ${counter}= set variable ${counter+1} ${counter}= evaluate ${counter} + 1 我希望每次运行关键字时,变量

我想创建一个robot关键字,每次调用它都会增加一个数字,但我无法让它工作

我尝试了几种实现增量的方法,有些只是给出了错误。下面的代码将通过,但请将变量保持在其原始值

*** Variables ***
${counter}=  ${1}

*** Keywords ***
my keyword
    ${counter}=  set variable  ${counter+1}
    ${counter}=  evaluate  ${counter} + 1
我希望每次运行关键字时,变量都会增加1,但它保持其原始值1。我在这里做错了什么?

这个

*** Variables ***
${counter}=     ${1}

*** Test Cases ***
Test
    My Keyword
    Log To Console    In test: ${counter}
    My Keyword

*** Keywords ***
my keyword
    ${counter}=  set variable  ${counter+1}
    ${counter}=  evaluate  ${counter} + 1
    Log To Console    In keyword: ${counter}
印刷品:

In keyword: 3
In test: 1
In keyword: 3
如果在
my keyword
中使用
Set Test Variable
,它将更新更大范围内的变量(测试范围,而不是关键字范围)

现在打印:

In keyword: 3
In test: 3
In keyword: 5
这个

印刷品:

In keyword: 3
In test: 1
In keyword: 3
如果在
my keyword
中使用
Set Test Variable
,它将更新更大范围内的变量(测试范围,而不是关键字范围)

现在打印:

In keyword: 3
In test: 3
In keyword: 5