我正在用 python 函式撰寫機器人測驗用例。我有一個像這樣的python函式
def ParseJSONUserData(jsonstring):
if len(jsonstring) == 0:
print("String is empty. No processing is possible.")
json_dict = json.loads(jsonstring)
if len(json_dict) == 0:
print("No data found in file.")
currentdt = json_dict[CURRENTDATETIME]
if len(currentdt) == 0:
print ("The Current datetime property is empty")
print ("Systems found: ", len( json_dict[SYSTEMS]))
if len(json_dict[SYSTEMS]) == 0 :
print("No systems found!")
for system_result in json_dict[SYSTEMS]:
if system_result[SERIALNUM] in systems:
print ("Duplicate systemserialnumber value: " system_result[SERIALNUM] )
systems.add(system_result[SERIALNUM])
if len(system_result[PUBKEYS][0]["pubkey"]) == 0 :
print("No pubkey found for system: " system_result[SERIALNUM] )
if len(system_result[PUBKEYS][0]["system"]) == 0 :
print("No pubkey system designator (typically intraop) found for system: " system_result[SERIALNUM] )
這是我的機器人框架代碼。
${response}= GET ${host}/data ${data} headers=${header}
${op}= ParseJSONUserData response.json()
Log to console ${op}
我正在嘗試任何一項驗證在 python 中都失敗了。它應該在機器人代碼中失敗。但是,即使我傳遞了錯誤的資料,python 函式也會被執行,并且機器人測驗用例也會成功。任何幫助都感激不盡。
uj5u.com熱心網友回復:
要使關鍵字失敗,它必須引發例外。不是列印字串,而是引發錯誤。例如:
if len(jsonstring) == 0:
raise Exception("String is empty. No processing is possible.")
有關更多資訊,請參閱機器人框架用戶指南中的報告關鍵字統計資訊,其中說:
報告關鍵字狀態只需使用例外即可。如果執行的方法引發例外,關鍵字status為FAIL,如果正常回傳,則status為PASS。
可以使用 AssertionError、ValueError 和 RuntimeError 等標準例外來報告正常執行失敗和錯誤。但是,在隨后的部分中解釋了一些需要特殊例外的特殊情況。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512635.html
上一篇:黑杰克,將卡值加在一起的問題
