Skip to content
Snippets Groups Projects

[test][python] allow to overwrite the interpreter for python test command

Merged Christian Engwer requested to merge feature/python-test-interpreter into master
3 unresolved threads
1 file
+ 35
11
Compare changes
  • Side-by-side
  • Inline
@@ -4,15 +4,30 @@
#
# .. cmake_param:: SCRIPT
# :multi:
# :required:
#
# The script to execute using the python interpreter. It will be executed during :code:`make test_python`
# and during `ctest`.
# and during `ctest`. You are required to either pass SCRIPT or MODULE.
#
# .. note::
#
# The script will be executed using
# :code:`${Python3_EXECUTABLE} SCRIPT`.
# The script will be executed using :code:`${Python3_EXECUTABLE} SCRIPT`. If the INTERPRETER
# option is given, that interpreter is used instead.
#
# .. cmake_param:: MODULE
# :multi:
#
# The Python module to be executed. It will be executed during :code:`make test_python`
# and during `ctest`. You are required to either pass SCRIPT or MODULE.
#
# .. note::
#
# The script will be executed using :code:`${Python3_EXECUTABLE} -m MODULE`. If the INTERPRETER
# option is given, that interpreter is used instead.
#
# .. cmake_param:: INTERPRETER
# :single:
#
# The Python interpreter to use for this test. It defaults to the one found by CMake.
#
# .. cmake_param:: WORKING_DIRECTORY
# :single:
@@ -36,9 +51,9 @@ function(dune_python_add_test)
# Parse Arguments
include(CMakeParseArguments)
set(OPTION)
set(SINGLE WORKING_DIRECTORY NAME)
set(MULTI SCRIPT COMMAND LABELS)
# set(MULTI COMMAND LABELS)
set(SINGLE WORKING_DIRECTORY NAME INTERPRETER)
set(MULTI SCRIPT COMMAND LABELS MODULE)
cmake_parse_arguments(PYTEST "${OPTION}" "${SINGLE}" "${MULTI}" ${ARGN})
if(PYTEST_COMMAND)
message(FATAL_ERROR "dune_python_add_test: COMMAND argument should not be used, use SCRIPT instead providing only the Python script and not the Python interpreter")
@@ -48,11 +63,20 @@ function(dune_python_add_test)
endif()
# Apply defaults
if(NOT PYTEST_INTERPRETER)
set(PYTEST_INTERPRETER ${Python3_EXECUTABLE})
endif()
if(NOT PYTEST_WORKING_DIRECTORY)
set(PYTEST_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(NOT PYTEST_SCRIPT)
message(FATAL_ERROR "dune_python_add_test: no SCRIPT to execute specified!")
if((NOT PYTEST_MODULE) AND (NOT PYTEST_SCRIPT))
message(FATAL_ERROR "dune_python_add_test: Either SCRIPT or MODULE need to be specified!")
endif()
if(PYTEST_MODULE AND PYTEST_SCRIPT)
message(FATAL_ERROR "dune_python_add_test: You can only specify either SCRIPT or MODULE, not both!")
endif()
if(PYTEST_MODULE)
set(PYTEST_SCRIPT -m ${PYTEST_MODULE})
endif()
if(NOT PYTEST_NAME)
set(commandstr "")
@@ -65,7 +89,7 @@ function(dune_python_add_test)
# Actually run the command
add_custom_target(target_${PYTEST_NAME}
COMMAND ${Python3_EXECUTABLE} ${PYTEST_SCRIPT}
COMMAND ${PYTEST_INTERPRETER} ${PYTEST_SCRIPT}
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY})
# Build this during make test_python
@@ -75,7 +99,7 @@ function(dune_python_add_test)
dune_declare_test_label(LABELS ${PYTEST_LABELS})
# Also build this during ctest
_add_test(NAME ${PYTEST_NAME}
COMMAND ${Python3_EXECUTABLE} ${PYTEST_SCRIPT}
COMMAND ${PYTEST_INTERPRETER} ${PYTEST_SCRIPT}
WORKING_DIRECTORY ${PYTEST_WORKING_DIRECTORY}
)
# Set the labels on the test
Loading