我正在尝试运行官方的 RF 计算器示例,通过提及 pythonpath 参数指向.py文件 (CalculatorLibrary.py)
当我从命令行将 pythonpath 传递给 pybot 时,它可以工作
[centos6 tmp]$ pybot -t "Push multiple buttons" -t "Push button" --pythonpath RobotDemo/ RobotDemo
==============================================================================
RobotDemo
==============================================================================
RobotDemo.Keyword Driven :: Example test cases using the keyword-driven tes...
==============================================================================
Push button | PASS |
------------------------------------------------------------------------------
Push multiple buttons | PASS |
------------------------------------------------------------------------------
RobotDemo.Keyword Driven :: Example test cases using the keyword-d... | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
RobotDemo | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Output: /tmp/output.xml
Log: /tmp/log.html
Report: /tmp/report.html
但是当我使用运行 api 执行此操作时,它不起作用
这是代码
import robot
abs_master_suite_path = "RobotDemo"
testcases_tobe_run_list = ["Push multiple buttons","Push button"]
this_path = ["RobotDemo"]
ret = robot.run(abs_master_suite_path, test=testcases_tobe_run_list, pythonpath=this_path)
这是我得到的输出
[centos6 tmp]$ python run_pybot.py
==============================================================================
RobotDemo
==============================================================================
[ ERROR ] Error in file '/tmp/RobotDemo/keyword_driven.txt': Importing test library 'CalculatorLibrary' failed: ImportError: No module named CalculatorLibrary
Traceback (most recent call last):
None
PYTHONPATH:
/usr/local/lib/python2.7/site-packages/robot/libraries
/usr/local/lib/python2.7/site-packages
/tmp
/usr/local/lib/python2.7/site-packages/virtualenv-1.8.4-py2.7.egg
/usr/local/lib/python2.7/site-packages/plumbum-1.1.0-py2.7.egg
/usr/local/lib/python2.7/site-packages/six-1.2.0-py2.7.egg
/usr/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg
/usr/local/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg
/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4b4-py2.7-linux-i686.egg
/usr/local/lib/python2.7/site-packages/Pinax-0.9a2-py2.7.egg
/usr/local/lib/python2.7/site-packages/configparser-3.3.0r2-py2.7.egg
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
.
RobotDemo.Keyword Driven :: Example test cases using the keyword-driven tes...
==============================================================================
Push button | FAIL |
No keyword with name 'Push button' found.
------------------------------------------------------------------------------
Push multiple buttons | FAIL |
No keyword with name 'Push button' found.
------------------------------------------------------------------------------
RobotDemo.Keyword Driven :: Example test cases using the keyword-d... | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
RobotDemo | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output: /tmp/output.xml
Log: /tmp/log.html
Report: /tmp/report.html
RF无法找到给定的python路径
在这种情况下,我错了还是射频有问题
最近遇到了同样的问题。在访问robot.run API之前,您可以通过导入robot.pythonpathsetter并调用add_path来手动添加所需的pythonpath。但是,这可能会导致程序中其他位置出现意外的副作用,因此在测试完成运行后,您可能希望调用remove_path。
例如:
from robot import pythonpathsetter
pythonpathsetter.add_path(additional_python_path)
robot.run(test_suite)
pythonpathsetter.remove_path(additional_python_path)
'ROBOT' 有两个函数来运行测试。
run():运行测试的函数。
run_cli():使用命令行参数处理运行测试的函数。
在'Python27\Lib\site-packages\robot\utils\application.py'
def execute_cli(self, cli_arguments):
with self._logging():
options, arguments = self._parse_arguments(cli_arguments)
rc = self._execute(arguments, options)
self._exit(rc)
def execute(self, *arguments, **options):
with self._logging():
return self._execute(list(arguments), options)
"execute_cli"调用"self._parse_arguments(cli_arguments)",因此可以使用参数"pythonpath"。"def parse_args"→"_handle_special_options"方法"_handle_special_options"调用
if self._auto_pythonpath and opts.get('pythonpath'):
sys.path = self._get_pythonpath(opts['pythonpath']) + sys.path
所以你必须更新方法'def execute'
def execute(self, *arguments, **options):
with self._logging():
if options['pythonpath']:
sys.path=[options['pythonpath']]+sys.path
del options['pythonpath']
return self._execute(list(arguments), options)