py.test is know tool for testing Python scripts. I am missing, however, CMake macro for the detetion of py.test.
Is there anything of this kind within CMake pool of macros ?
py.test is know tool for testing Python scripts. I am missing, however, CMake macro for the detetion of py.test.
Is there anything of this kind within CMake pool of macros ?
Directly calling py.test from a CMakeLists.txt isn't very portable, because different systems name it quite differently, e.g.:
py.test # pip, as of early 2018
pytest # ditto
py.test-3 # Fedora 26 package
pytest-3 # ditto
Of course, the system might default to version 2 or 3, and might have both version 2 and 3 installed side by side.
Thus, a simple method for reliable executing right pytest version via cmake is to invoke pytest differently:
python3 -m pytest
(instead of py.test or pytest or ...)
If you want to test in cmake if the pytest package is available you can test this with execute_process(), e.g.:
execute_process(COMMAND python3 -m pytest --version
OUTPUT_VARIABLE PYTEST_output
ERROR_VARIABLE PYTEST_error
RESULT_VARIABLE PYTEST_result)
if(${PYTEST_result} UNEQUAL 0)
message(SEND_ERROR "Pytest package not available: ${PYTEST_error}")
endif()