python - 是否可以有一个空值的场景大纲表?

标签 python bdd gherkin

场景大纲:Blah de blah 当我输入并在输入字段上时 那么一切都很好

例子:
|一个 | b |
| 1 | 2 |
| | 3 |

上述场景在 BBD Behave 中抛出以下错误 测试未定义 请定义测试

我不确定如何解决这个问题。 有什么建议么?

最佳答案

使用 https://pypi.org/project/parse/ 中描述的自定义类型转换

import parse

from behave import given, register_type


@parse.with_pattern(r'.*')
def parse_nullable_string(text):
    return text


register_type(NullableString=parse_nullable_string)

@given('params "{a:NullableString}" and "{b:NullableString}"'
def set_params(context, a, b):
  # a or b will be empty if they are blank in the Examples
  context.a = a
  context.b = b

现在特征文件看起来像这样,

Given params "<a>" and "<b>"
# Rest of the steps
Examples:
 | a | b |
 | 1 | 2 |
 |   | 3 |

关于python - 是否可以有一个空值的场景大纲表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29298550/

相关文章:

ruby-on-rails - Rails 3 测试框架困惑

css - Watir - 使用 CSS 元素

java - Gherkin - 你如何用英语编写明确的测试用例?

python - 如何在 peewee 中创建自引用的多对多字段?

python - Django:如何创建自定义 "base"模型

javascript - 使用 Sinon 测试 JavaScript 点击事件

java - 作为 cucumber 运行功能未在 Eclipse 中显示

go - 如何在 golang 中从 Gherkin 数据表中输入 bool 值?

python - 通过网络共享间歇性 'OSError: [Errno 2] No such file or directory'

java - uuid5 实现中命名空间是必需的吗?