【发布时间】:2021-04-25 02:40:50
【问题描述】:
我正在尝试使用机器人框架测试 python 文件,我的部分文件采用 -i 选项,输入文件是从命令行提供的。我希望能够从命令行设置 inputFile。如果不能在 Robot Framework 中使用 -i 选项,有没有办法在我的 .robot 文件中显式设置 inputFile 变量?
这里有一些代码供参考:
parser = argparse.ArgumentParser(add_help=True, description='Usage')
parser.add_argument('-i', dest='input_file', required=True, help='Input module (servicenow, nagios, splunk etc.) containing its implementation')
parser.add_argument('-c', '--check', action='store_true', required=False, help='Flag to check connections to OVGD and input module.')
# Check and parse the input arguments into python's format
inputFile = parser.parse_args()
#inputFile = "duplicate_module_simple_logging.py"
inputModuleName = inputFile.input_file.split(".")[0]
#inputModuleName = inputFile.split(".")[0]
#gModuleName = inputModuleName
separator = os.sep
temp = inputModuleName.split(separator)
以下是我尝试的一些选项,但我不确定我是否了解如何在 Robot 中传递输入参数:
[root@xxxxxx]# robot --variable inputFile:duplicate_module_simple_logging.py test2.robot
==============================================================================
Test2
==============================================================================
Case1 | PASS |
------------------------------------------------------------------------------
Case2 | FAIL |
TypeError: string indices must be integers
------------------------------------------------------------------------------
Case3 | PASS |
------------------------------------------------------------------------------
Case4 | PASS |
------------------------------------------------------------------------------
Case5 usage: robot [-h] -i INPUT_FILE [-c]
robot: error: the following arguments are required: -i
[ ERROR ] Execution stopped by user.
这是我的测试文件的样子:
*** Settings ***
Library String
Library Collections
Library duplicate_main.py
Library duplicate_module_simple_logging.py
*** Variables ***
${inputFile} duplicate_module_simple_logging.py
*** Test Cases ***
Case1
${result1} = init logger_module
Should Be Equal As Integers ${result1} 0
Case2
${result2} = execute alert
Should Be Equal As Integers ${result2} 0
Case3
${result3} = cleanup
Should Be Equal As Integers ${result3} 0
Case4
${result4} = init 8
Should Be Equal As Integers ${result4} 0
Case5
${result5} = main
Should Be Equal As Integers ${result5} 0
【问题讨论】:
标签: python linux unit-testing robotframework command-line-arguments