Skip to content

Commit

Permalink
Address API change in Python 3.12 unittest module (#4852)
Browse files Browse the repository at this point in the history
Starting with Python 3.12, package `unittest` returns exit code 5 when all tests are skipped. By default, CTest treats any non-zero exit code as a failure. This can be remediated by setting test property [`SKIP_RETURN_CODE`](https://cmake.org/cmake/help/latest/prop_test/SKIP_RETURN_CODE.html) to 5.

Description of changes:
- skipped tests are no longer treated as failures by CTest
  • Loading branch information
kodiakhq[bot] authored Jan 30, 2024
2 parents da47129 + 9f221cf commit 5cc8361
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions testsuite/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ function(python_test)
add_test(${TEST_NAME} ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${TEST_FILE_CONFIGURED} ${TEST_ARGUMENTS})
endif()
set_tests_properties(${TEST_NAME} PROPERTIES PROCESSORS ${TEST_NUM_PROC}
DEPENDS "${TEST_DEPENDS}")

if(${TEST_GPU_SLOTS} GREATER 0 AND ESPRESSO_BUILD_WITH_CUDA)
set_property(TEST ${TEST_NAME} PROPERTY RESOURCE_GROUPS
Expand All @@ -117,7 +115,10 @@ function(python_test)
if(${TEST_NUM_PROC} EQUAL 3)
list(APPEND TEST_LABELS "parallel_odd")
endif()
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${TEST_LABELS}")

set_tests_properties(
${TEST_NAME} PROPERTIES PROCESSORS ${TEST_NUM_PROC} SKIP_RETURN_CODE 5
DEPENDS "${TEST_DEPENDS}" LABELS "${TEST_LABELS}")

set(python_tests ${python_tests} ${TEST_FILE_CONFIGURED} PARENT_SCOPE)
endfunction(python_test)
Expand Down
6 changes: 3 additions & 3 deletions testsuite/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ macro(PYTHON_SCRIPTS_TEST)
string(REGEX REPLACE "^test_" "${TEST_TYPE}_" TEST_NAME ${TEST_NAME})
add_test(${TEST_NAME} ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${TEST_FILE_CONFIGURED})
set_tests_properties(${TEST_NAME} PROPERTIES FIXTURES_REQUIRED
IMPORTLIB_WRAPPER)
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${TEST_LABELS}")
set_tests_properties(
${TEST_NAME} PROPERTIES FIXTURES_REQUIRED IMPORTLIB_WRAPPER
SKIP_RETURN_CODE 5 LABELS "${TEST_LABELS}")
if("gpu" IN_LIST TEST_LABELS AND ESPRESSO_BUILD_WITH_CUDA)
set_tests_properties(${TEST_NAME} PROPERTIES RESOURCE_LOCK GPU)
endif()
Expand Down
5 changes: 3 additions & 2 deletions testsuite/scripts/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ endfunction(BENCHMARK_TEST)
# configure Python module importlib_wrapper.py
add_test(importlib_wrapper ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER})
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set_tests_properties(
importlib_wrapper PROPERTIES FIXTURES_SETUP IMPORTLIB_WRAPPER
SKIP_RETURN_CODE 5)
set(benchmarks_tests ${benchmarks_tests}
${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER} PARENT_SCOPE)
configure_file(../importlib_wrapper.py
Expand Down
5 changes: 3 additions & 2 deletions testsuite/scripts/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ endfunction(SAMPLE_TEST)
# configure Python module importlib_wrapper.py
add_test(importlib_wrapper ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER})
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set_tests_properties(
importlib_wrapper PROPERTIES FIXTURES_SETUP IMPORTLIB_WRAPPER
SKIP_RETURN_CODE 5)
set(samples_tests ${samples_tests} ${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER}
PARENT_SCOPE)
configure_file(../importlib_wrapper.py
Expand Down
6 changes: 3 additions & 3 deletions testsuite/scripts/tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ add_test(importlib_wrapper ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER})
add_test(convert ${CMAKE_BINARY_DIR}/pypresso ${PYPRESSO_OPTIONS}
${CMAKE_CURRENT_BINARY_DIR}/test_convert.py)
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set_tests_properties(convert PROPERTIES FIXTURES_SETUP IMPORTLIB_WRAPPER)
set_tests_properties(
importlib_wrapper convert PROPERTIES FIXTURES_SETUP IMPORTLIB_WRAPPER
SKIP_RETURN_CODE 5)
set(tutorials_tests ${tutorials_tests} ${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER}
PARENT_SCOPE)
configure_file(../importlib_wrapper.py
Expand Down

0 comments on commit 5cc8361

Please sign in to comment.