Python 2.7 RobotFramework:提升密码执行不起作用

Python 2.7 RobotFramework:提升密码执行不起作用,python-2.7,robotframework,Python 2.7,Robotframework,我们正在使用RobotFramework实现自动化。在我们的一个python模块中,我们希望在python代码中使用passexecution来通过测试状态 我尝试使用raisepassexecution,但是我得到的只是一条消息,但是测试用例没有停止就继续进行。我还尝试调用关键字pass_execution,但看到了相同的行为 有人能告诉我怎么做吗 这是我的密码 def fetchData(productType , attributes=[]): result_Array = fet

我们正在使用RobotFramework实现自动化。在我们的一个python模块中,我们希望在python代码中使用passexecution来通过测试状态

我尝试使用raisepassexecution,但是我得到的只是一条消息,但是测试用例没有停止就继续进行。我还尝试调用关键字pass_execution,但看到了相同的行为

有人能告诉我怎么做吗

这是我的密码

def fetchData(productType , attributes=[]):
    result_Array = fetch_url_response(productType , attributes)
    iterator = 1
    data_List = list()
    while(iterator < len(result_Array)):
        try:
            data_List.append((result_Array[iterator])[1:11])
            iterator = iterator + 1
        except Exception as ex:
            print ex
        # Shuffles the List of data
    random.shuffle(data_List) 
    print "Checking the data Length."
    if len(data_List) < 1:
        print "Length less than 1. Pass the Execution"
        #call_keyword('pass_execution' , 'No data found for the criteria. Passing the test case')
        raise PassExecution('No data found for the criteria. Passing the test case')
    else:
        data = data_List[0]
        return data
def fetchData(productType,attributes=[]):
结果\u数组=获取\u url\u响应(产品类型、属性)
迭代器=1
数据列表=列表()
while(迭代器
如果看不到您的代码,就不可能知道您做错了什么

关键字有两种方式可使测试立即停止并处于通过状态:引发
robot.errors.PassExecution
异常,或调用内置关键字
PASS\u execution

下面是使用每种方法的两个关键字的示例:

from robot.libraries.BuiltIn import BuiltIn
from robot.errors import PassExecution

def custom_keyword_1():
    BuiltIn().pass_execution("life is good")

def custom_keyword_2():
    raise PassExecption("life is still good")
要测试它,请将其保存到名为“custom_keywords.py”的文件中,并按如下方式使用:

*** Settings ***
| Library | custom_keywords.py

*** Test cases ***
| Example 1
| | log | before calling the custom keyword
| | custom keyword 1
| | log | after calling the custom keyword

| Example 2
| | log | before calling the custom keyword
| | custom keyword 2
| | log | after calling the custom keyword

运行上述程序时,您应该会看到第一条日志消息和“life is good”消息,但在每个测试中都不会看到最后一条日志消息,因为测试立即以“pass”状态结束。

事实上,我的代码与您提到的相同。在输出中,我可以看到发送到PassExecution的消息,但测试没有停止,而是继续进行。@Shari:那么,根据上面的确切代码,您是说您在每个测试中都看到了“调用后…”日志消息?是的,我在控制台中看到了“调用后…”消息,消息“生活很好”…你用的是什么版本的机器人?这应该行得通。您的日志是否显示任何其他错误或警告?我使用的是2.8(最新版本)。除了其他关键字运行和抛出错误之外,没有其他警告。