acc960830bf3cad7c55d74fd041ba7fff924726e
[alexxy/gromacs.git] / python_packaging / sample_restraint / tests / CMakeGROMACS.txt
1 # This file holds some additional scripting that is used for the automated
2 # testing of the GROMACS project. The file is only processed when building as
3 # part of the full GROMACS build.
4
5
6 # Make sure pytest is found or produce a fatal error
7 if(NOT GMXAPI_PYTEST_FOUND)
8     execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pytest; print(pytest.__version__)"
9                     RESULT_VARIABLE pytest_not_found OUTPUT_VARIABLE pytest_version ERROR_QUIET)
10     if(pytest_not_found)
11         message(FATAL_ERROR "Running the tests requires pytest. Please install it manually"
12                 " (try: ${PYTHON_EXECUTABLE} -m pip install pytest)")
13     elseif(pytest_version VERSION_LESS 3.0)
14         message(FATAL_ERROR "Running the tests requires pytest >= 3.0. Found: ${pytest_version}"
15                 "Please update it (try: ${PYTHON_EXECUTABLE} -m pip install -U pytest)")
16     endif()
17     set(GMXAPI_PYTEST_FOUND TRUE CACHE INTERNAL "Suppress checking for Python pytest module.")
18 endif()
19
20 # TODO: (#2961) Let the Python package discover required resources instead of passing GMXBIN
21 get_target_property(GMXBIN gmx RUNTIME_OUTPUT_DIRECTORY)
22 get_target_property(GMXAPI_PYTHON_STAGING_DIR _gmxapi staging_dir)
23 get_target_property(PLUGINPATH gmxapi_extension LIBRARY_OUTPUT_DIRECTORY)
24 add_custom_target(gmxapi_extension_pytest
25                   COMMAND ${CMAKE_COMMAND} -E env GMXBIN=${GMXBIN} PYTHONPATH=${GMXAPI_PYTHON_STAGING_DIR}
26                   ${PYTHON_EXECUTABLE} -m pytest --log-cli-level ERROR ${CMAKE_CURRENT_SOURCE_DIR}
27                   DEPENDS gmxapi_extension _gmxapi
28                   WORKING_DIRECTORY ${PLUGINPATH})
29 # The current test fixtures require the `gmx` tool-wrapper executable.
30 add_dependencies(gmxapi_extension_pytest gmx)
31
32 add_dependencies(tests gmxapi_extension_histogram-test gmxapi_extension_bounding-test)
33
34 add_dependencies(check gmxapi_extension_pytest)