diff --git a/doc/manual/sphinx/source/test_items/lua_func_test_item.rst b/doc/manual/sphinx/source/test_items/lua_func_test_item.rst index 9662d3f..efbbb6a 100644 --- a/doc/manual/sphinx/source/test_items/lua_func_test_item.rst +++ b/doc/manual/sphinx/source/test_items/lua_func_test_item.rst @@ -64,7 +64,7 @@ In the example above, the global variable ``$(lfn_activity)`` would be created at the end of the item execution. It would contain the resulting value of the funcToBeExecuted python function. -**Global variables** +**Lua Interpreter environment setup** Some global variables have an impact on the ``lua_func`` test item behavior: diff --git a/doc/manual/sphinx/source/test_items/py_func_test_item.rst b/doc/manual/sphinx/source/test_items/py_func_test_item.rst index 55ec449..8f7da53 100644 --- a/doc/manual/sphinx/source/test_items/py_func_test_item.rst +++ b/doc/manual/sphinx/source/test_items/py_func_test_item.rst @@ -107,10 +107,22 @@ In the example above, the global variable ``$(pfn_function test item)`` would be created at the end of the item execution. It would contain the resulting value of the funcToBeExecuted python function. -**Global variables** +**Python Interpreter environment setup** Some global variables have an impact on the ``py_func`` test item behavior: * ``python_path``: This optional global variable can be used to define the python executable path. If not defined, the python interpreter is searched in at the default places in the system. +* ``python_env``: This global variable can be used to define + environment variables for the lua script execution environment. + Only `PATH`, `LUA_PATH`, and `LUA_CPATH` are supported. + + .. code-block:: yaml + :caption: example of configuration file: param.yaml + + [...] + python_env: + PATH: "/my/path/" + PYTHONPATH: "/my/python/modules/" + [...] \ No newline at end of file diff --git a/src/testium/interpreter/utils/icons.py b/src/testium/interpreter/utils/icons.py index 9049d61..58e3208 100644 --- a/src/testium/interpreter/utils/icons.py +++ b/src/testium/interpreter/utils/icons.py @@ -6,7 +6,7 @@ def icon_prefix(): if not hasattr(prefs, "settings"): prefs.init() - if isinstance(prefs.settings.icons_theme, int) and 0 <= prefs.settings.icons_theme < len(cst.ICON_THEMES_PREFIX): + if isinstance(prefs.settings.icons_theme, int) and (0 <= prefs.settings.icons_theme < len(cst.ICON_THEMES_PREFIX)): return cst.ICON_THEMES_PREFIX[prefs.settings.icons_theme] else: return cst.ICON_THEMES_PREFIX[0] \ No newline at end of file diff --git a/src/testium/interpreter/utils/py_func_exec.py b/src/testium/interpreter/utils/py_func_exec.py index b970b48..38f0971 100644 --- a/src/testium/interpreter/utils/py_func_exec.py +++ b/src/testium/interpreter/utils/py_func_exec.py @@ -1,3 +1,4 @@ +import os import sys import shutil import subprocess @@ -69,6 +70,22 @@ class PyFuncExecEngine: if self._process is not None: raise ETUMRuntimeError("The function subprocess has already been started.") + # POpen config + CUST_ENV = { + "PATH": {"replace": False}, + "PYTHONPATH": {"replace": True}, + } + + py_env = tm.gd("python_env", {}) + env = os.environ.copy() + for k, v in CUST_ENV.items(): + e = py_env.get(k, "") + if e != "": + if v["replace"]: + env[k] = e + else: + env[k] = e + ";" + env.get(k, "") + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("localhost", 0)) self._port = sock.getsockname()[1] @@ -81,7 +98,7 @@ class PyFuncExecEngine: params.append("-v") self._process = subprocess.Popen( - params, cwd=func_proc_path + params, env=env, cwd=func_proc_path ) # Port was reserved until the sub-process is started. Now released.