首页 > 解决方案 > 无法根据机器人框架中的标签运行测试套件设置

问题描述

我有一个测试套件,其中包含 5 个测试,并结合了不同的测试标签,如下所示

*** Settings ***
Test Setup           Perform Test Setup

*** Test Cases ***
TC1
    [Tags]  preprod
    log to console  preprod tests : test1

TC2
    [Tags]  Debug
    log to console  debug tests : test2

TC3
    [Tags]  preprod  Debug
    log to console  debug and prerod : test3

*** Keywords ***
Perform Test Setup
    log to console  Test Cases With Tag To Run Are : @{TEST TAGS}
    Run Keyword If  'Debug' in ${TEST TAGS}
    ...  log to console  Debug Test Starting

    Run Keyword If  'preprod' in ${TEST TAGS}
    ...    log to console  preprod tests starting

现在,当我使用标签运行以下命令时

robot -i preprod sample.robot

甚至来自 Perform Test Setup of condition hpt 的关键字也在运行。

=============================================================================
Sample                                                                        
==============================================================================
TC1                                                                   Test Cases With Tag To Run Are : ['preprod']
preprod tests starting
.preprod tests : test1
TC1                                                                   | PASS |
------------------------------------------------------------------------------
TC3                                                                   Test Cases With Tag To Run Are : ['Debug', 'preprod']
Debug Test Starting
preprod tests starting
.debug and prerod : test3
TC3                                                                   | PASS |
------------------------------------------------------------------------------
Sample                                                                | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================

'Debug' == ${TEST TAGS}执行测试设置条件下,关键字根本不执行。

如何在测试中基于具有多个标签和组合的标签运行测试套件设置或 TearDown

标签: pythonrobotframework

解决方案


推荐阅读