Adjust python module path in __init__, add checks to pytest

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.
This commit is contained in:
Monty Montgomery 2022-05-15 00:29:37 -04:00
parent 5d0e69c7ed
commit 97d3c1ce9e
2 changed files with 28 additions and 8 deletions

View File

@ -2,8 +2,8 @@ import os
import sys
from . import config
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH))
_netgen_bin_dir=os.path.realpath(os.path.join(config.NG_INSTALL_DIR_PYTHON,config.NETGEN_PYTHON_RPATH_BIN))
_netgen_lib_dir=os.path.realpath(os.path.join(config.NG_INSTALL_DIR_PYTHON,config.NETGEN_PYTHON_RPATH))
if sys.platform.startswith('win'):
if sys.version >= '3.8':

View File

@ -1,8 +1,28 @@
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 1800 )
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)