setup pythonpath before starting test suite

血红的双手。 提交于 2019-12-04 19:37:27

You can't do what you want. The settings are all processed before any test or keyword is run. You can use the --pythonpath option from the command line, or set the environment variable PYTHONPATH before starting your test.

You can do it by adding to sys.path in suite init. E.g. you can create __init__.robot file in tests directory with:

*** Settings ***
Suite Setup    Setup before all tests

*** Keywords ***
Setup before all tests
    evaluate    sys.path.append(os.path.join("path", "to", "library"))    modules=os, sys

Described in official docs: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#configuring-sys-path-programmatically

I'm not sure if this would work, but I think there actually might be a way to do what you're talking about. It's pretty jenky, so bear with me.

You can't really do it in Robot Framework, but if you expand your horizons to Python, there's a neat little exploit I've found. If you take a look in other posts how to create a custom Python Library for Robot framework, you'll notice that there's a required method called __init__ with parameters of (self). I believe that this is the very first code to run when the Library instance is created. Little-known fact, you can add parameters to the creation of the Library instance. In your case, ~/Test_suite would be the value that you would pass.

IN THEORY, because I haven't tried this, you could tell __init__(self, path_in) to run your BuiltIn keyword with the following code:

self.BuiltIn().set_environment_variable('PYTHONPATH', path_in)

Don't forget to use the following import statement at the top of the file.

from robot.libraries.BuiltIn import BuiltIn
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!