From 86f173f5f32b471bad20ef92e7d9794fb39cb158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 1 Jun 2024 12:10:59 +0200 Subject: [PATCH] Fix tests by using PYTHONPATH if no paths specified when initializing runner. --- src/runner/pythonrunner.cpp | 6 ++++++ tests/runner/CMakeLists.txt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 54f4019..6a3b813 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -85,6 +85,9 @@ namespace mo2::python { // initialize the core Path of Python, this must be done before // initialization // + // TODO: use config.module_search_paths, config.module_search_paths_set and + // config.pythonpath_env instead of Py_SetPath + // if (!pythonPaths.empty()) { QStringList paths; for (auto const& p : pythonPaths) { @@ -92,6 +95,9 @@ namespace mo2::python { } Py_SetPath(paths.join(';').toStdWString().c_str()); } + else if (auto* pythonPathEnv = _wgetenv(L"PYTHONPATH")) { + Py_SetPath(pythonPathEnv); + } PyConfig config; PyConfig_InitIsolatedConfig(&config); diff --git a/tests/runner/CMakeLists.txt b/tests/runner/CMakeLists.txt index 71a6843..73e344c 100644 --- a/tests/runner/CMakeLists.txt +++ b/tests/runner/CMakeLists.txt @@ -39,7 +39,7 @@ string(APPEND extra_paths "\\;${PYTHON_ROOT}/PCbuild/amd64") string(APPEND extra_paths "\\;$") set_tests_properties(${runner-tests_gtests} PROPERTIES - WORKING_DIRECTORY "${MO2_INSTALL_PATH}/bin" ENVIRONMENT "PLUGIN_DIR=${CMAKE_CURRENT_SOURCE_DIR}/plugins" ENVIRONMENT_MODIFICATION - "PATH=path_list_prepend:${extra_paths};PYTHONPATH=set:${PYTHONPATH}") + "PATH=path_list_prepend:${extra_paths};PYTHONPATH=set:${PYTHONPATH}" +)