亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

行為步驟消歧/可選步驟參數

行為步驟消歧/可選步驟參數

茅侃侃 2024-01-15 21:17:53
我正在嘗試支持以下功能場景: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 parsefrom behave import step, [email protected]_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我認為我真的不需要一個可選參數,只要我可以消除第一個示例中的步驟的歧義即可。
查看完整描述

1 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

在使用 Behave 時,我注意到在步驟定義文件中定義步驟的順序很重要。


嘗試首先從最具體的步驟開始定義您的步驟:


@step('attacked by {opponent} from {direction}')

def step_attacked_by(context, opponent, direction):

    print(opponent)

    print(direction)


@step('attacked by {opponent}')

def step_attacked_by(context, opponent):

    print(opponent)

運行你的 test.feature 不會再給我帶來歧義錯誤。


查看完整回答
反對 回復 2024-01-15
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號