You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python BDD无法解析Feature示例数据,仅获取占位符文本问题

Python BDD无法解析Scenario Outline示例数据问题解决

问题现象

使用最新版本Python BDD时,尝试将Feature文件中的示例值解析到Python代码,发现只能获取占位符文本<parameters>,无法拿到Examples里的实际示例数据。

相关代码与Feature文件

Python步骤定义代码

@given(parsers.parse("{parameters}"), target_fixture="parameters", converters={"parameters": str})
def ParseParmeters(parameters):
    return parameters

Feature文件内容

Feature:check if data of given attributes is NOT NULL
    Scenario outline: Duplicate_check
        Given <parameters>
        When SQL to execute:
            SELECT  
            '%TST_CD' AS Test_Cd
            ,(select failurename from table where ='NO_ROWS_RETURNED'
            )  tst_SQL
            WHERE tst_SQL.tst_Result = 'Fail';
        Then EXPECTED_RESULT=NO_ROWS_RETURNED

        Examples:
        | parameters |
        | TST_CD=Duplicate_check;Data_Entity=LIT;PROCESS_NAME=procname;Data_Attribute=DA1,DA2;Proc_Typ_Cd=P3 |

解决方案

将普通的Scenario替换为Scenario Outline(注:提供的Feature文件已修正,原问题根源是最初使用了Scenario而非Scenario Outline),替换后Python BDD就能正确关联Examples表格中的数据,将实际参数值传递给步骤定义函数,而非占位符文本。

内容的提问来源于stack exchange,提问作者h ca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 08:58:18