Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CMake py.test检测?_Cmake_Pytest - Fatal编程技术网

CMake py.test检测?

CMake py.test检测?,cmake,pytest,Cmake,Pytest,是测试Python脚本的著名工具。但是,我缺少用于py.test测试的CMake宏 在CMake宏池中有这种类型的东西吗?从CMakeLists.txt直接调用py.test不是很容易移植,因为不同的系统对它的命名非常不同,例如: py.test # pip, as of early 2018 pytest # ditto py.test-3 # Fedora 26 package pytest-3 # ditto 当然,系统可能默认为版本2或3,并且可能同时安装了版本2和

是测试Python脚本的著名工具。但是,我缺少用于py.test测试的CMake宏


在CMake宏池中有这种类型的东西吗?

CMakeLists.txt
直接调用
py.test
不是很容易移植,因为不同的系统对它的命名非常不同,例如:

py.test    # pip, as of early 2018
pytest     # ditto
py.test-3  # Fedora 26 package
pytest-3   # ditto
当然,系统可能默认为版本2或3,并且可能同时安装了版本2和版本3

因此,通过cmake可靠执行正确pytest版本的简单方法是:

(而不是
py.test
pytest
或…)

如果您想在cmake中测试pytest软件包是否可用,您可以使用,例如:

python3 -m pytest
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()