在测试用例中间设置robotframework拆卸关键字

时间:2018-09-18 06:48:12

标签: python robotframework

我从查阅和阅读机器人框架用户指南知道,机器人框架具有“拆卸”选项,在测试用例或套件的末尾,它调用可用于清除的关键字。

我正在尝试将此拆解用于测试中间的对象(我导入的库)。

*** Settings ***
Test Timeout     10 minutes
Library          OperatingSystem
Library          String


*** Variables ***
${SUPER_SCRIPT_NAME}    Test

*** Test Cases ***
Dummy
    [Documentation]
    LOG    HEllo xyz blha blah
    Should Be True    4 < 8    msg=*ERROR* 4 is not greater than 8
    Import Library    ${CURDIR}/dummy.py    WITH NAME    dummy_obj
    dummy_obj.start_inside_dummy_obj    ${data_from_arg}
    Do Something Else For 4 Min
    Do Something Else For 4 Min
    dummy_obj.start_inside_secondary_obj    ${other_arg_data}
    Do Something Else For 4 Min
    dummy_obj.cleanup_everything    # inside this main_obj calls inside_dummy_obj.cleanup(), which calls inside_secondary_obj.cleanup().  Once "inside_secondary_obj" cleanup() is complete inside_dummy_obj.cleanup() is completed, which completes dummy_obj's cleanup_everything()

这是我遇到的问题:我导入并创建python库的对象(将其称为“ dummy_obj”),将其导入并在内部创建对象(将其称为“ inside_dummy_obj”),然后导入并创建一个对象在里面(我们称其为“ inside_secondary_obj”)。在正常情况下,测试成功完成,我调用导入的库/对象关键字进行清理,其中“ main_obj”调用“ inside_main_obj”的清理,后者调用“ inside_secondary_obj”的清理;所有它们的清理都会按顺序进行。

如果要中止(Cntrl-C)的发出,我需要能够在“ 4秒钟做其他事情”期间调用“ dummy_obj.cleanup_everything”关键字。

我不知道是否可以动态设置Teardown关键字,因为在创建dummy_obj对象之前不需要设置它。我尝试对所有python del ()对象进行实验,但似乎并没有按顺序删除它们。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我想我误解了测试用例的拆卸。刚刚这样做,似乎可以正常工作:

*** Settings ***
Test Timeout     10 minutes
Library          OperatingSystem
Library          String


*** Variables ***
${SUPER_SCRIPT_NAME}    Test

*** Test Cases ***
Dummy
    [Documentation]
    LOG    HEllo xyz blha blah
    Should Be True    4 < 8    msg=*ERROR* 4 is not greater than 8
    Import Library    ${CURDIR}/dummy.py    WITH NAME    dummy_obj
    dummy_obj.start_inside_dummy_obj    ${data_from_arg}
    Do Something Else For 4 Min
    Do Something Else For 4 Min
    dummy_obj.start_inside_secondary_obj    ${other_arg_data}
    Do Something Else For 4 Min
    dummy_obj.cleanup_everything    # inside this main_obj calls inside_dummy_obj.cleanup(), which calls inside_secondary_obj.cleanup().  Once "inside_secondary_obj" cleanup() is complete inside_dummy_obj.cleanup() is completed, which completes dummy_obj's cleanup_everything()
    [Teardown]    dummy_obj.cleanup