I’d like to use CTest to run some Python scripts; however, I need to run them with a different version of Python from the one which my system defaults to.
Getting the tests to run with the correct version of Python is easy enough: I just make sure that PYTHON_EXECUTABLE is defined correctly and then:
add_test(NAME SimplePythonTest
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/SimpleTest.py
WORKING_DIRECTORY ${my_home})
However, if this is all I do, then the global PYTHONPATH and PYTHONHOME environment variables still point to the system default version, and this will cause the tests to fail. As it happens, all the Python modules I want to use are in my custom version’s site-packages and it can find them directly, so if I run the tests from the command line (i.e. not via CMake at all) then all I have to do is type:
set PYTHONHOME=
set PYTHONPATH=
… and then it works.
I can’t find a syntax to do the equivalent for CTest, though. Alongside many other guesses which gave configuration-time errors, I’ve tried both:
set_tests_properties(SimplePythonTest
PROPERTIES ENVIRONMENT "PYTHONHOME="
ENVIRONMENT "PYTHONPATH=")
and
set_tests_properties(SimplePythonTest
PROPERTIES ENVIRONMENT PYTHONHOME=${THE_CORRECT_PYTHONHOME}
ENVIRONMENT PYTHONPATH=${THE_CORRECT_PYTHONPATH})
…but neither works. If I run the tests with CTest --verbose then the output shows:
1354: Environment variables:
1354: PYTHONPATH=
1354: Test timeout computed to be: 10000000
or
1354: Environment variables: 1354: PYTHONPATH=< the correct path that I specified > 1354: Test timeout computed to be: 10000000
…which seems to indicate that set_tests_properties is only setting PYTHONPATH and leaving PYTHONHOME at its default.
So, what is the correct syntax for setting (or, preferably, unsetting altogether) both environment variables simultaneously?