Skip to content

Commit b6f9587

Browse files
authored
Use pytest to generate junit xml files for python tests (#446)
Signed-off-by: ahcorde <ahcorde@gmail.com>
1 parent 73b23d1 commit b6f9587

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

.github/ci/packages.apt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ libignition-cmake2-dev
33
libpython3-dev
44
python3-distutils
55
python3-pybind11
6+
python3-pytest
67
ruby-dev
78
swig

src/python_pybind11/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,25 @@ if (BUILD_TESTING)
141141
Vector4_TEST
142142
)
143143

144+
execute_process(COMMAND "${Python3_EXECUTABLE}" -m pytest --version
145+
OUTPUT_VARIABLE PYTEST_output
146+
ERROR_VARIABLE PYTEST_error
147+
RESULT_VARIABLE PYTEST_result)
148+
if(${PYTEST_result} EQUAL 0)
149+
set(pytest_FOUND TRUE)
150+
else()
151+
message("")
152+
message(WARNING "Pytest package not available: ${PYTEST_error}")
153+
endif()
154+
144155
foreach (test ${python_tests})
145-
add_test(NAME ${test}.py COMMAND
146-
"${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py")
156+
if (pytest_FOUND)
157+
add_test(NAME ${test}.py COMMAND
158+
"${Python3_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml")
159+
else()
160+
add_test(NAME ${test}.py COMMAND
161+
"${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py")
162+
endif()
147163

148164
set(_env_vars)
149165
list(APPEND _env_vars "PYTHONPATH=${FAKE_INSTALL_PREFIX}/lib/python/")

0 commit comments

Comments
 (0)