@@ -178,31 +178,43 @@ if(XCSF_PYLIB)
178178 file (COPY ${PYTHON_EXAMPLES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
179179 file (COPY "xcsf/utils/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR} /xcsf/utils/ )
180180 file (COPY "xcsf/__init__.py" DESTINATION ${CMAKE_CURRENT_BINARY_DIR} /xcsf/ )
181+
181182 if (PYTEST)
182183 # Copy the Python tests
183184 file (GLOB PYTHON_TESTS "test/python/*.py" )
184185 file (COPY ${PYTHON_TESTS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
186+
187+ # Check Python executable has been found
188+ if (NOT Python_EXECUTABLE)
189+ message (FATAL_ERROR "Python_EXECUTABLE is not set" )
190+ endif ()
191+
185192 # Create a virtual environment
186193 set (VENV_DIR "${CMAKE_CURRENT_BINARY_DIR} /venv" )
187- execute_process (COMMAND "${PYTHON_EXECUTABLE} " -m venv "${VENV_DIR} " )
194+ execute_process (COMMAND "${Python_EXECUTABLE} " -m venv "${VENV_DIR} " )
195+
188196 # Activate the virtual environment
189197 if (WIN32 )
190198 set (PYTHON_EXEC "${VENV_DIR} /Scripts/python" )
191199 else ()
192200 set (PYTHON_EXEC "${VENV_DIR} /bin/python" )
193201 endif ()
202+
194203 # Install dependencies
195204 execute_process (
196205 COMMAND "${PYTHON_EXEC} " -m pip install pytest numpy scikit-learn
197206 )
207+
198208 # Add pytest to ctest (to capture CI failures)
199209 add_test (NAME pytest COMMAND "${PYTHON_EXEC} " -m pytest . )
210+
200211 # Execute pytest at the end of building
201212 add_custom_target (run_tests ALL
202213 COMMAND "${PYTHON_EXEC} " -m pytest .
203214 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
204215 COMMENT "Running pytest..."
205216 )
217+
206218 # Wait for XCSF to be built
207219 add_dependencies (run_tests xcsf )
208220 endif ()
0 commit comments