gpt4 book ai didi

python - 如何预期 Python 中机器人框架的失败?

转载 作者:行者123 更新时间:2023-12-04 16:00:29 25 4
gpt4 key购买 nike

我们在工作中使用robot framework做一些自动化测试,我需要添加一些测试。这种格式已经在 repo 中,我不能做任何大的改变。

我正在使用如下所示的关键字文件:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from robot.api.deco import keyword

class testkeywords(object):
"""
"""

def __init__(self):
pass

@keyword('I compare ${first_number} with ${second_number}')
def compare(self, first_number, second_number):
if (int(first_number) != int(second_number)):
raise ValueError('Numbers are not the same.')

.robot 文件有两个测试,一个通过,一个失败:

*** Settings ***
Library testkeywords.py

*** Variables ***
${num_a} 5
${num_b} 6

*** Test Cases ***
Compare same numbers
I compare ${num_a} with ${num_a}

Compare different numbers
I compare ${num_a} with ${num_b}

Compare different numbers 测试如预期的那样失败了,但它仍然是 FAIL。我如何设置它以预期失败并因此传递关键字?

最佳答案

我想通了。您可以只修改测试以预期出现如下错误:

Compare different numbers
Run Keyword And Expect Error * I compare ${num_a} with ${num_b}

或者查找特定错误(而不是通配符):

Compare different numbers
Run Keyword And Expect Error ValueError: Numbers are not the same. I compare ${num_a} with ${num_b}

注意命令、错误和关键字之间的双空格。

关于python - 如何预期 Python 中机器人框架的失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com