我正在尝试支持以下功能场景:
Feature: test
Scenario: Test optional
Given attacked by samurai
And attacked by samurai from behind
我的步骤文件是
from behave import step
@step('attacked by {opponent}')
def step_attacked_by(context, opponent):
print(opponent)
@step('attacked by {opponent} from {direction}')
def step_attacked_by(context, opponent, direction):
print(opponent)
print(direction)
我收到错误:
behave.step_registry.AmbiguousStep: @step('attacked by {opponent} from {direction}') has already been defined in
existing step @step('attacked by {opponent}') at steps/test.py:5
然后我尝试使用可选参数:
我的功能文件:
Feature: test
Scenario: Test optional
Given attacked by a samurai
我的步骤文件:
import parse
from behave import step, register_type
@parse.with_pattern(r"a\s+")
def parse_word_a(text):
"""Type converter for "a " (followed by one/more spaces)."""
return text.strip()
register_type(a_=parse_word_a)
@step('attacked by {:a_?}{opponent}')
def step_attacked_by(context, a_, opponent):
print(a_)
print(opponent)
我收到此错误:
raise ValueError('format spec %r not recognised' % type)
ValueError: format spec 'a_?' not recognised
我认为我真的不需要一个可选参数,只要我可以消除第一个示例中的步骤的歧义即可。
湖上湖
相关分类