Skip to content

Commit 86b7fac

Browse files
taylorhoward92mergify[bot]
authored andcommitted
Fix Python test PYTHONPATH: use ENVIRONMENT_MODIFICATION instead of ENVIRONMENT (#584)
* Fix Python test PYTHONPATH: use ENVIRONMENT_MODIFICATION instead of ENVIRONMENT The Python test environment setup in python/CMakeLists.txt uses set_tests_properties(... ENVIRONMENT "PYTHONPATH=...") which overwrites any PYTHONPATH set in the shell environment and bakes CMAKE_INSTALL_PREFIX paths that don't exist at test time (before install). Replace with ENVIRONMENT_MODIFICATION using path_list_prepend (CMake 3.22+) to prepend CMAKE_BINARY_DIR/lib to PYTHONPATH and LD_LIBRARY_PATH at test-execution time, preserving any paths already set in the environment. Signed-off-by: Taylor Howard <taylorhoward@me.com> Generated-by: Claude <noreply@anthropic.com> (cherry picked from commit ca96b71)
1 parent 353496f commit 86b7fac

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

python/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ if (BUILD_TESTING AND NOT WIN32)
3030
add_test(NAME ${test}.py COMMAND
3131
"${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/test/${test}.py")
3232
endif()
33-
set(_env_vars "PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/")
34-
set_tests_properties(${test}.py PROPERTIES ENVIRONMENT "${_env_vars}")
33+
set(_env_vars)
34+
list(APPEND _env_vars "PYTHONPATH=path_list_prepend:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/")
35+
list(APPEND _env_vars "PYTHONPATH=path_list_prepend:${CMAKE_BINARY_DIR}/gz_msgs_gen/python/")
36+
if(APPLE)
37+
list(APPEND _env_vars "DYLD_LIBRARY_PATH=path_list_prepend:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
38+
list(APPEND _env_vars "DYLD_LIBRARY_PATH=path_list_prepend:${CMAKE_BINARY_DIR}/lib")
39+
else()
40+
list(APPEND _env_vars "LD_LIBRARY_PATH=path_list_prepend:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
41+
list(APPEND _env_vars "LD_LIBRARY_PATH=path_list_prepend:${CMAKE_BINARY_DIR}/lib")
42+
endif()
43+
set_tests_properties(${test}.py PROPERTIES
44+
ENVIRONMENT_MODIFICATION "${_env_vars}")
3545
endforeach()
3646
endif()

0 commit comments

Comments
 (0)