netgen/tests/pytest/CMakeLists.txt

29 lines
1.4 KiB
CMake
Raw Normal View History

if(USE_PYTHON)
if(ENABLE_UNIT_TESTS)
set(PYTHON_UNIT_TESTS TRUE)
# check for prerequisite modules
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pytest; print(pytest.__file__)"
OUTPUT_VARIABLE pytest_path RESULT_VARIABLE pytest_result)
if(NOT ${pytest_result} EQUAL 0)
message(WARNING "python module 'pytest' not found.")
set(PYTHON_UNIT_TESTS FALSE)
endif()
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pytest_check; print(pytest_check.__file__)"
OUTPUT_VARIABLE pycheck_path RESULT_VARIABLE pycheck_result)
if(NOT ${pytest_result} EQUAL 0)
message(WARNING "python module 'pytest_check' not found.")
set(PYTHON_UNIT_TESTS FALSE)
endif()
if(PYTHON_UNIT_TESTS)
add_test(NAME pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(pytest ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_tests_properties ( pytest PROPERTIES TIMEOUT 18000 )
if(USE_MPI AND USE_MPI4PY)
add_test(NAME pytest-mpi COMMAND ${MPIEXEC_EXECUTABLE} --allow-run-as-root -np 4 ${PYTHON_EXECUTABLE} -m pytest --with-mpi test_mpi4py.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif(USE_MPI AND USE_MPI4PY)
else()
message(WARNING "Unable to perform unit tests on netgen python modules.")
endif()
endif()
endif(USE_PYTHON)