Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pytest-cov optional for -DNRN_ENABLE_TESTS #1250

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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