第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

python 行為中不同步驟名稱顯示的不明確步驟異常

python 行為中不同步驟名稱顯示的不明確步驟異常

呼喚遠(yuǎn)方 2023-04-25 16:47:58
我在 steps 目錄下有兩個(gè)不同的 python 文件: driverlogon.py和 triplogon.pydriverlogon.py定義步驟@when(u'enter the {driver_id}')def step_enter_the_driver_id(context,driver_id):    SelectDriver.input_driver(driver_id)triplogon.py定義步驟@when(u'enter the configured block number')def step_enter_the_configured_block_number(context):    ByBlock.enter_block(context.block)當(dāng)我運(yùn)行這個(gè)程序時(shí),我收到以下錯(cuò)誤消息,在這種情況下,它們有不同的文本,甚至函數(shù)的內(nèi)容也不同。為什么會(huì)這樣,誰(shuí)能幫我理解這個(gè)?提前致謝Exception AmbiguousStep: @when('enter the configured block number') has already been defined in  existing step @when('enter the {driver_id}') at steps/driverlogon.py:26Traceback (most recent call last):  File "C:\Program Files (x86)\Python\Lib\runpy.py", line 193, in _run_module_as_main    "__main__", mod_spec)  File "C:\Program Files (x86)\Python\Lib\runpy.py", line 85, in _run_code    exec(code, run_globals)  File "C:\Program Files (x86)\Python\Scripts\behave.exe\__main__.py", line 7, in <module>  File "c:\program files (x86)\python\lib\site-packages\behave\__main__.py", line 183, in main    return run_behave(config)  File "c:\program files (x86)\python\lib\site-packages\behave\__main__.py", line 127, in run_behave    failed = runner.run()  File "c:\program files (x86)\python\lib\site-packages\behave\runner.py", line 804, in run    return self.run_with_paths()  File "c:\program files (x86)\python\lib\site-packages\behave\runner.py", line 809, in run_with_paths    self.load_step_definitions()  File "c:\program files (x86)\python\lib\site-packages\behave\runner.py", line 796, in load_step_definitions    load_step_modules(step_paths)  File "c:\program files (x86)\python\lib\site-packages\behave\runner_util.py", line 412, in load_step_modules    exec_file(os.path.join(path, name), step_module_globals)  File "c:\program files (x86)\python\lib\site-packages\behave\runner_util.py", line 386, in exec_file    exec(code, globals_, locals_)  File "steps\triplogon.py", line 23, in <module>
查看完整描述

4 回答

?
蠱毒傳說(shuō)

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

歧義問(wèn)題來(lái)自另一個(gè)方向,并且不能總是通過(guò)使用雙引號(hào)來(lái)解決。歧義可能仍然存在。

正確的解決方案是對(duì)參數(shù)使用類型模式,否則將使用所有格解析器并盡可能多地消耗——為假定的重復(fù)項(xiàng)留出空間。


查看完整回答
反對(duì) 回復(fù) 2023-04-25
?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

作為一種解決方案,如果您想保留這些名稱,您可以這樣寫(xiě):


driverlogon.py


@when(u'enter the "{driver_id}"')

def step_enter_the_driver_id(context,driver_id):

     SelectDriver.input_driver(driver_id)

triplogon.py


@when(u'enter the configured block number') 

def step_enter_the_configured_block_number(context):

   ByBlock.block_data(context.block)

在這種情況下不會(huì)引發(fā)異常,但 driver_id 將作為字符串傳遞,步驟將如下所示:


When enter the "10"


但是,如果您希望它被解析為 int 而不是您可以d在這種情況下使用預(yù)定義的數(shù)據(jù)類型,如下所示:


@when(u'enter the "{driver_id:d}"')

def step_enter_the_driver_id(context,driver_id):

     SelectDriver.input_driver(driver_id)

https://behave.readthedocs.io/en/latest/parse_builtin_types.html


查看完整回答
反對(duì) 回復(fù) 2023-04-25
?
滄海一幻覺(jué)

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

我將在此處提取該behave 問(wèn)題結(jié)果以總結(jié)解決方案。


將類型說(shuō)明符添加到參數(shù)(例如:S 或:d)


 @when(u'enter the {driver_id:S}')

 def step_enter_the_driver_id(context,driver_id):

     SelectDriver.input_driver(driver_id)


 @when(u'enter the configured block number')

 def step_enter_the_configured_block_number(context):

     ByBlock.enter_block(context.block)

先放更復(fù)雜(更長(zhǎng)?)的定義。所以如果你把它放在一個(gè)文件中,它將是:


 @when(u'enter the configured block number')

 def step_enter_the_configured_block_number(context):

     ByBlock.enter_block(context.block)


 @when(u'enter the {driver_id}')

 def step_enter_the_driver_id(context,driver_id):

     SelectDriver.input_driver(driver_id)

或者檢查重命名文件是否有效,如果具有更復(fù)雜定義的文件按字母順序排列在另一個(gè)文件之前。


查看完整回答
反對(duì) 回復(fù) 2023-04-25
?
千萬(wàn)里不及你

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊

步驟定義的工作方式如下:

  • 你新建一個(gè)py文件

  • 您向該文件添加一個(gè)新的函數(shù)定義

    • 在這種情況下,您的兩個(gè)文件都具有相同的函數(shù)名稱,def step_impl

  • 你用你想要與之關(guān)聯(lián)的功能文件文本裝飾你的新功能

    • enter the {driver_id}

    • enter the configured block number

  • 當(dāng)您運(yùn)行 behave 時(shí),該程序會(huì)收集其所有特征文件及其所有步驟定義,然后嘗試將兩者關(guān)聯(lián)起來(lái)

  • 對(duì)于上面的示例,Behave 找到文本enter the {driver_id},并將其與函數(shù)相關(guān)聯(lián)step_impl

  • 然后 Behave 找到文本enter the configured block number,并嘗試將其與其函數(shù)定義相關(guān)聯(lián),但發(fā)現(xiàn)函數(shù)step_impl已經(jīng)被定義并與特征文本相關(guān)聯(lián)。不知道該怎么做,Behave 拋出AmbiguousStep異常讓你知道一個(gè)函數(shù)名被使用了兩次。

要解決此問(wèn)題,您需要確保您的函數(shù)名稱在所有步驟定義文件中都是唯一的。因此,在您的情況下,您有兩個(gè)文件,每個(gè)文件都定義了一個(gè)名為step_impl. 您應(yīng)該做的是用唯一名稱重命名這些函數(shù),以便 Behave 可以在運(yùn)行時(shí)正確關(guān)聯(lián)這些名稱。為確保名稱是唯一的,我建議選擇與裝飾文本緊密匹配的名稱。如果是我寫(xiě)這些定義,我會(huì)重寫(xiě)如下:

driverlogon.py


@when(u'enter the {driver_id}')

def step_enter_the_driver_id(context,driver_id):

     SelectDriver.input_driver(driver_id)

triplogon.py


@when(u'enter the configured block number') 

def step_enter_the_configured_block_number(context):

   ByBlock.block_data(context.block)

編輯#1:


感謝您包含堆棧跟蹤。由此看來(lái),您在兩個(gè)不同的文件中兩次定義了相同的步驟:


File "steps\triplogon.py", line 23, in <module>

    @when(u'enter the configured block number')

  File "c:\program files (x86)\python\lib\site-packages\behave\step_registry.py", line 92, in wrapper

    self.add_step_definition(step_type, step_text, func)

  File "c:\program files (x86)\python\lib\site-packages\behave\step_registry.py", line 58, in add_step_definition

    raise AmbiguousStep(message % (new_step, existing_step))

behave.step_registry.AmbiguousStep: @when('enter the configured block number') has already been defined in

  existing step @when('enter the {driver_id}') at steps/driverlogon.py:26

你會(huì)注意到在第一行它說(shuō):


File "steps\triplogon.py", line 23, in <module>

    @when(u'enter the configured block number')

表示該步驟enter the configured block number定義在triplogon.py


然后跟蹤的最后一行說(shuō):


behave.step_registry.AmbiguousStep: @when('enter the configured block number') has already been defined in

  existing step @when('enter the {driver_id}') at steps/driverlogon.py:26

這表明enter the configured block number也已在中定義driverlogon.py


確保僅在兩個(gè)文件之一中定義了該步驟。


查看完整回答
反對(duì) 回復(fù) 2023-04-25
  • 4 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)