【问题标题】:Set to Dictionary keyword from collections not accepting positional arguments从不接受位置参数的集合中设置为字典关键字
【发布时间】:2020-09-03 18:55:20
【问题描述】:

我正在使用集合中的set to dictionary 关键字将键设置为string,将值设置为list,但这样做时出现错误说明:

关键字Collections.Set To Dictionary在命名参数之后得到了位置参数。

我希望它声明它不会接受列表作为值,我是这个框架的新手。我有一个场景可以将我的测试结果作为列表传递给其他函数以及一个键。任何人都可以帮助我或提供解决方法来实现它。请在下面找到我的一段代码:

@{result_list}=    create list    ${TEST_NAME}    "User Should be logged in"    ${Actualresult}   ${Status}

set to dictionary    &{Test_result_dict}    ${tid}    ${result_list}

如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: python robotframework


    【解决方案1】:

    我认为这行:

    set to dictionary    &{Test_result_dict}    ${tid}    ${result_list}
    

    应该改为:

    set to dictionary    ${Test_result_dict}    ${tid}    ${result_list}
    

    因此,您应该使用$ 而不是&。这意味着您将变量称为标量而不是字典。这是documentation的相关部分。

    Dictionary variable syntax 描述了您的具体问题。

    在实践中,这意味着字典的各个项目是 作为命名参数传递给关键字。假设一个变量 &{USER} 的值为 {'name': 'robot', 'password': 'secret'},即 以下两个测试用例是等价的。

    *** Test Cases *** Constants
        Login    name=robot    password=secret
    
    Dict Variable
        Login    &{USER}
    

    当您使用 & 时,字典的元素将作为命名参数传递,这会导致 ${tid}${result_list} 变量导致“命名参数后的位置参数”错误。

    当您使用$ 时,字典本身将被传递。

    【讨论】:

      猜你喜欢
      • 2018-11-14
      • 2020-05-12
      • 2023-03-31
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      相关资源
      最近更新 更多