[Bf-blender-cvs] [2da25273506] temp-D7478-unittest-python-exe: Tests: On Linux, use Python from install dir

Sybren A. Stüvel noreply at git.blender.org
Fri Apr 24 10:17:03 CEST 2020


Commit: 2da252735061094367ddc70e0521f3f8ef90abb1
Author: Sybren A. Stüvel
Date:   Fri Apr 10 10:35:17 2020 +0200
Branches: temp-D7478-unittest-python-exe
https://developer.blender.org/rB2da252735061094367ddc70e0521f3f8ef90abb1

Tests: On Linux, use Python from install dir

CentOS on the buildbot still runs Python 3.6, which is also used for the
unit tests. This means that the tests can't use language features that
are available to Blender itself. And testing with a different version of
Python than will be used by the actual code seems like a bad idea to me.

This commit tries to find Python in the installation directory, which
will not be there on the first time CMake is run, so it also tries to
find it in the precompiled libraries. If that also fails, it defaults to
whichever Python executable CMake finds.

Differential Revision: https://developer.blender.org/D7395

===================================================================

M	tests/CMakeLists.txt
M	tests/python/CMakeLists.txt

===================================================================

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 94b6e49181c..18123da22bd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,7 +20,28 @@ elseif(APPLE)
   set(TEST_PYTHON_EXE)
 else()
   set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender)
-  set(TEST_PYTHON_EXE)
+
+  # Search for the Python executable to use in the tests.
+  # The installation directory's Python is the best one to use. However, it can only be there after the install step, which means
+  # that Python will never be here on a fresh system. This is why the search continues to the pre-built libraries, and if that
+  # doesn't exist either, default to whatever Python CMake found.
+  set(_python_exe "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python${PYTHON_VERSION}m")
+  if(EXISTS ${_python_exe})
+    message(STATUS "Tests: Using Python from installation directory: ${_python_exe}")
+    set(TEST_PYTHON_EXE ${_python_exe})
+  else()
+    set(_python_exe "${LIBDIR}/python/bin/python${PYTHON_VERSION}m")
+    if(EXISTS ${_python_exe})
+      message(STATUS "Tests: Using Python from pre-compiled LIBDIR: ${_python_exe}")
+      set(TEST_PYTHON_EXE ${_python_exe})
+    elseif(EXISTS ${PYTHON_EXECUTABLE})
+      message(STATUS "Tests: Using Python from PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
+      set(TEST_PYTHON_EXE ${PYTHON_EXECUTABLE})
+    else()
+      message(FATAL_ERROR "Tests: unable to find a Python executable to run the tests.")
+    endif()
+  endif()
+  unset(_python_exe)
 endif()
 
 # For testing with Valgrind
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index db5d5dcf73b..4b3a1ff9c45 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -48,7 +48,7 @@ endfunction()
 
 # Run Python script outside Blender.
 function(add_python_test testname testscript)
-  if(MSVC)
+  if(TEST_PYTHON_EXE)
     add_test(
       NAME ${testname}
       COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN}



More information about the Bf-blender-cvs mailing list