diff --git a/.github/ci/packages.apt b/.github/ci/packages.apt index 7d7fbbe02..a3086382a 100644 --- a/.github/ci/packages.apt +++ b/.github/ci/packages.apt @@ -3,5 +3,6 @@ libignition-cmake2-dev libpython3-dev python3-distutils python3-pybind11 +python3-pytest ruby-dev swig diff --git a/src/python_pybind11/CMakeLists.txt b/src/python_pybind11/CMakeLists.txt index 22adef2d0..5967f17dc 100644 --- a/src/python_pybind11/CMakeLists.txt +++ b/src/python_pybind11/CMakeLists.txt @@ -141,9 +141,25 @@ if (BUILD_TESTING) Vector4_TEST ) + execute_process(COMMAND "${Python3_EXECUTABLE}" -m pytest --version + OUTPUT_VARIABLE PYTEST_output + ERROR_VARIABLE PYTEST_error + RESULT_VARIABLE PYTEST_result) + if(${PYTEST_result} EQUAL 0) + set(pytest_FOUND TRUE) + else() + message("") + message(WARNING "Pytest package not available: ${PYTEST_error}") + endif() + foreach (test ${python_tests}) - add_test(NAME ${test}.py COMMAND - "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py") + if (pytest_FOUND) + add_test(NAME ${test}.py COMMAND + "${Python3_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml") + else() + add_test(NAME ${test}.py COMMAND + "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py") + endif() set(_env_vars) list(APPEND _env_vars "PYTHONPATH=${FAKE_INSTALL_PREFIX}/lib/python/")