From 2b206997c851f80e97f7fb8b6979fd4a686e6619 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Wed, 5 May 2021 09:24:35 +0200 Subject: [PATCH] make pytest-cov optional --- CMakeLists.txt | 9 +++++++-- test/CMakeLists.txt | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aab63b0fc..4901d5b087 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b3692d2a49..7348037714 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -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) @@ -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() @@ -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.