Question

I am trying to run the official RF calculator example, by mentioning the pythonpath argument to point to the .py file (CalculatorLibrary.py)

When I pass pythonpath to pybot from command line, it works

[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

But when I do this using the run api , it doesnt work

This is the code

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)

And this is the output I got

[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 is not able to find the given pythonpath

Am I wrong or is there something wrong with RF in this case

Était-ce utile?

La solution

Just recently ran into this same problem. You can manually add your desired pythonpath before hitting the robot.run API by importing robot.pythonpathsetter and calling add_path. This could potentially result in unintended side effects elsewhere in your program, however, so you'll probably want to call remove_path once the test is done running.

eg:

from robot import pythonpathsetter
pythonpathsetter.add_path(additional_python_path)
robot.run(test_suite)
pythonpathsetter.remove_path(additional_python_path)

Autres conseils

'ROBOT' has two functions to run tests.

run(): Function to run tests.

run_cli(): Function to run tests with command line argument processing.

In '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' call 'self._parse_arguments(cli_arguments)',so argument 'pythonpath' can be used. 'def parse_args' → '_handle_special_options' the method '_handle_special_options' call

        if self._auto_pythonpath and opts.get('pythonpath'):
        sys.path = self._get_pythonpath(opts['pythonpath']) + sys.path

So you must to update method '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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top