From b6f9587b728aeb0408bb655ca11083beff3256f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 29 Jun 2022 15:06:03 -0700 Subject: [PATCH] Use pytest to generate junit xml files for python tests (#446) Signed-off-by: ahcorde --- .github/ci/packages.apt | 1 + src/python_pybind11/CMakeLists.txt | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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/")