From b320597697d8c28798342ffc45a330f86ed276ca Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 3 Nov 2022 11:48:47 +1100 Subject: [PATCH] Tests: don't create byte-code cache when calling Python from SVN Creating `__pycache__` directories in SVN's lib/ directory can cause updating SVN to fail. Add the -B flag when TEST_PYTHON_EXE from LIBDIR is used so so Python doesn't generate this cache. --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 13 +++++++++++++ tests/blender_as_python_module/CMakeLists.txt | 2 +- tests/python/CMakeLists.txt | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e89943714a..810a6b011fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -550,6 +550,7 @@ endif() option(WITH_GTESTS "Enable GTest unit testing" OFF) option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF) option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF) +# NOTE: All callers of this must add `TEST_PYTHON_EXE_EXTRA_ARGS` before any other arguments. set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests") mark_as_advanced(TEST_PYTHON_EXE) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 68fcfc89b96..d2fbec7059f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,19 @@ elseif(NOT EXISTS ${TEST_PYTHON_EXE}) endif() +# Include these arguments before all others, they must not interfere with Python execution. +set(TEST_PYTHON_EXE_EXTRA_ARGS) + +# Check if this a Blender managed Python installation, if so, don't add `*.pyc` files. +if(LIBDIR) + cmake_path(IS_PREFIX LIBDIR "${TEST_PYTHON_EXE}" NORMALIZE _is_prefix) + if(_is_prefix) + # Keep the Python in Blender's SVN LIBDIR pristine, to avoid conflicts on updating. + set(TEST_PYTHON_EXE_EXTRA_ARGS "-B") + endif() + unset(_is_prefix) +endif() + # For testing with Valgrind # set(TEST_BLENDER_EXE valgrind --track-origins=yes --error-limit=no ${TEST_BLENDER_EXE}) diff --git a/tests/blender_as_python_module/CMakeLists.txt b/tests/blender_as_python_module/CMakeLists.txt index 6e0ce524903..7387d5c41bf 100644 --- a/tests/blender_as_python_module/CMakeLists.txt +++ b/tests/blender_as_python_module/CMakeLists.txt @@ -8,7 +8,7 @@ function(add_blender_as_python_module_test testname testscript) add_test( NAME ${testname} - COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN} + COMMAND ${TEST_PYTHON_EXE} ${TEST_PYTHON_EXE_EXTRA_ARGS} ${testscript} ${ARGN} ) # On macOS, asan library must be loaded early. diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index b3decc06161..0d74cfafda5 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -41,7 +41,7 @@ function(add_python_test testname testscript) add_test( NAME ${testname} - COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN} + COMMAND ${TEST_PYTHON_EXE} ${TEST_PYTHON_EXE_EXTRA_ARGS} ${testscript} ${ARGN} ) set_tests_properties(${testname} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0:$ENV{LSAN_OPTIONS}