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.
This commit is contained in:
Campbell Barton 2022-11-03 11:48:47 +11:00
parent bad55d56bc
commit b320597697
4 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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})

View File

@ -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.

View File

@ -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}