gpt4 book ai didi

python - __init__.txt 中定义的关键字不会被提取用于测试设置和测试拆卸

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:19 25 4
gpt4 key购买 nike

我想尝试用户定义的关键字作为机器人框架测试套件和子测试套件中测试用例的设置和拆卸。我有以下结构,

    ROOT    |    |- tests        |- __init__.txt        |- sample.robot

__init__.txt 包含以下文本

    *** Settings ***    Test Setup    My Keyword1    Test Teardown    My Keyword2    *** Keywords ***    My Keyword1        Log    Inside My Keyword1    My Keyword2        Log    Inside My Keyword2

Sample.robot 包含以下代码,

    *** Test Cases ***    My Testcase1        Log    Inside My Testcase1

运行 robot tests 给我以下错误,

    ==============================================================================    Tests    ==============================================================================    Tests.Sample    ==============================================================================    My Testcase1                                                          | FAIL |    Setup failed:    No keyword with name 'My Keyword1' found.    Also teardown failed:    No keyword with name 'My Keyword2' found.    ------------------------------------------------------------------------------    Tests.Sample                                                          | FAIL |    1 critical test, 0 passed, 1 failed    1 test total, 0 passed, 1 failed    ==============================================================================    Tests                                                                 | FAIL |    1 critical test, 0 passed, 1 failed    1 test total, 0 passed, 1 failed    ==============================================================================

你能告诉我在上面的结构中我遗漏了什么吗?我需要一种机制,允许我执行用户关键字作为默认设置或拆卸。此外,如果需要,单个测试用例可以覆盖设置/拆卸。

最佳答案

问题是 My Keyword1My Keyword2__init__.txt 文件中是本地的,不能在其他测试用例中使用。您需要将它们移动到资源文件中,并将该文件导入到您的测试中。

来自 initialization files 上的机器人框架用户指南部分:

Variables and keywords created or imported in initialization files are not available in the lower level test suites. If you need to share variables or keywords, you can put them into resource files that can be imported both by initialization and test case files.

关于python - __init__.txt 中定义的关键字不会被提取用于测试设置和测试拆卸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49754614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com