Skip to content

Commit

Permalink
Address API change in Python 3.12 unittest module (espressomd#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 and jngrad committed Feb 2, 2024
1 parent 7525b50 commit d09de49
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions testsuite/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function(PYTHON_TEST)
endif()
set_tests_properties(${TEST_NAME} PROPERTIES PROCESSORS ${TEST_NUM_PROC}
DEPENDS "${TEST_DEPENDS}")
set_tests_properties(${TEST_NAME} PROPERTIES SKIP_RETURN_CODE 5)

if("gpu" IN_LIST TEST_LABELS AND WITH_CUDA)
set_tests_properties(${TEST_NAME} PROPERTIES RESOURCE_LOCK GPU)
Expand Down
1 change: 1 addition & 0 deletions testsuite/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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 SKIP_RETURN_CODE 5)
set_tests_properties(${TEST_NAME} PROPERTIES FIXTURES_REQUIRED
IMPORTLIB_WRAPPER)
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${TEST_LABELS}")
Expand Down
1 change: 1 addition & 0 deletions testsuite/scripts/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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 SKIP_RETURN_CODE 5)
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set(benchmarks_tests ${benchmarks_tests}
Expand Down
1 change: 1 addition & 0 deletions testsuite/scripts/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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 SKIP_RETURN_CODE 5)
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set(samples_tests ${samples_tests} ${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/scripts/tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ 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 SKIP_RETURN_CODE 5)
set_tests_properties(importlib_wrapper PROPERTIES FIXTURES_SETUP
IMPORTLIB_WRAPPER)
set_tests_properties(convert PROPERTIES SKIP_RETURN_CODE 5)
set_tests_properties(convert PROPERTIES FIXTURES_SETUP IMPORTLIB_WRAPPER)
set(tutorials_tests ${tutorials_tests} ${TEST_FILE_CONFIGURED_IMPORTLIB_WRAPPER}
PARENT_SCOPE)
Expand Down

0 comments on commit d09de49

Please sign in to comment.