首页 > 解决方案 > Python表现Gherkin Step参数获取编译时间数字预期异常

问题描述

Feature: Step Parameter Test

  Scenario: look up a book
    Given I search for a valid book
    Then the result page will include "success"

  Scenario: look up an invalid book
    Given I search for a invalid book
    Then the result page will include "failure"

步骤定义:获取 {} 之间预期的异常编号,不考虑状态作为参数

@then('the result page will include {status}')
def step_impl(context,status):
    """
    :type context: behave.runner.Context
    """
    pass

异常截图: 在此处输入图像描述

在这种情况下,我什至尝试了正则表达式来获取步骤未定义的异常。没有找到任何方法将字符串/数字/双精度作为参数从功能文件中传递

请建议是否有办法解决这个问题。

标签: python-behave

解决方案


无论出于何种原因,您的behave解析器似乎都是're'. 通常是'parse'. 在您的测试文件中添加以下内容:

from behave import use_step_matcher

use_step_matcher('parse')
#the rest of your test here
#@given...

behave文档在use_step_matcher 这里


推荐阅读