mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-15 23:40:34 +05:00
97d3c1ce9e
Adjust path setup of the python modules in __init__ such that it's possible to run pytests from a mock root during package build/test. Also add checks to pytest/CMakelists.txt to make sure pytest abd check are present instead of failing with an inscrutible traceback if they're not installed or usable.
29 lines
1.4 KiB
CMake
29 lines
1.4 KiB
CMake
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)
|