Skip to content

Commit

Permalink
CMake: pytest-cov is now optional (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavulescu committed Jan 24, 2022
1 parent c9b6fb9 commit b91db0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,13 @@ if(NRN_ENABLE_TESTS)
include(CTest)
include(Catch)
find_python_module(pytest)
if(NRN_ENABLE_PYTHON AND NOT PYTEST_FOUND)
message(SEND_ERROR "pytest Python package is required.")
find_python_module(pytest_cov)
if(NRN_ENABLE_PYTHON)
if(NOT PYTEST_FOUND)
message(SEND_ERROR "pytest Python package is required.")
elseif(NOT PYTEST_COV_FOUND)
message(WARNING "pytest-cov package not installed. Python coverage will not be generated.")
endif()
endif()
# Initialize the submodule *before* including the test/CMakeLists.txt that uses it. This ensures
# that the test infrastructure can find the names of the input data files and set up rules to copy
Expand Down
13 changes: 8 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ endif()
# =============================================================================
if(NRN_ENABLE_PYTHON AND PYTEST_FOUND)
include(NeuronTestHelper)
if(PYTEST_COV_FOUND)
set(PYTEST_COVERAGE_ARGS --cov-report=xml --cov=neuron)
else()
endif()
# TODO: consider allowing the group-related parts to be dropped here
nrn_add_test_group(NAME pynrn_tests)
nrn_add_test(
GROUP pynrn_tests
NAME basic_tests
COMMAND COVERAGE_FILE=.coverage.basic_tests ${PYTHON_EXECUTABLE} -m pytest --cov-report=xml
--cov=neuron ./test/pynrn
COMMAND COVERAGE_FILE=.coverage.basic_tests ${PYTHON_EXECUTABLE} -m pytest ${PYTEST_COVERAGE_ARGS} ./test/pynrn
MODFILE_PATTERNS test/pynrn/*.mod
SCRIPT_PATTERNS test/pynrn/*.py)

Expand All @@ -133,7 +136,7 @@ if(NRN_ENABLE_PYTHON AND PYTEST_FOUND)
GROUP rxdmod_tests
NAME rxd_tests
COMMAND COVERAGE_FILE=.coverage.rxd_tests ${change_test_tolerance} ${PYTHON_EXECUTABLE} -m
pytest --cov-report=xml --cov=neuron ./test/rxd)
pytest ${PYTEST_COVERAGE_ARGS} ./test/rxd)
if(NRN_ENABLE_MPI)
find_python_module(mpi4py)
if(mpi4py_FOUND)
Expand All @@ -143,7 +146,7 @@ if(NRN_ENABLE_PYTHON AND PYTEST_FOUND)
COMMAND
COVERAGE_FILE=.coverage.rxd_mpi_tests ${change_test_tolerance} ${MPIEXEC_NAME}
${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${PYTHON_EXECUTABLE} ${MPIEXEC_POSTFLAGS}
-m pytest --cov-report=xml --cov=neuron ./test/rxd --mpi)
-m pytest ${PYTEST_COVERAGE_ARGS} ./test/rxd --mpi)
endif()
endif()
endif()
Expand Down Expand Up @@ -190,7 +193,7 @@ if(NRN_ENABLE_PYTHON AND PYTEST_FOUND)
-pyexe
${PYTHON_EXECUTABLE})
else()
set(py_args -m pytest --cov-report=xml --cov=neuron -s)
set(py_args -m pytest ${PYTEST_COVERAGE_ARGS}-s)
set(modtests_launch_py ${nrnpython_mpi_env} ${PYTHON_EXECUTABLE} ${py_args})
set(modtests_launch_hoc ${CMAKE_BINARY_DIR}/bin/nrniv ${nrniv_mpi_arg})
# This tries to use pytest and mpi4py in parallel, which might be fragile.
Expand Down

0 comments on commit b91db0e

Please sign in to comment.