python - 如何预期 Python 中的机器人框架会失败?
问题描述
我们在工作中使用机器人框架做一些自动化测试,我需要添加一些测试。这种格式已经在 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
按预期失败,但仍然失败。如何将其设置为预期失败并因此传递关键字?
解决方案
我想到了。您可以只修改测试以预期出现错误,如下所示:
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}
注意命令、错误和关键字之间的双空格。
推荐阅读
- memory - repr(C) 是预处理器指令吗?
- vue.js - 如何正确配置 vuelidate?
- html - 尝试将鼠标悬停在第一个和最后一个子菜单上时消失
- java - 计算两个坐标之间的距离 SQL + Criteria Builder
- jquery - 在 Angular 中动态更新 jQuery datepicker 属性
- python - 如何从与 Python 中的保留函数或关键字同名的模块中成功导入某些内容?
- r - 如何使用 ggplot2 和 plotly 制作交互式甜甜圈图?
- sql-server - BIML 中的嵌套查询
- javascript - 在 electron.js 中打开一个文件并从 Touch Bar 中单击一个按钮
- javascript - 不能同时发布和重定向