Skip to content

Commit

Permalink
Use pytest to generate junit xml files for python tests (#1562)
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde authored Jul 5, 2022
1 parent d6e69d0 commit 199237d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ libxi-dev
libxmu-dev
python3-distutils
python3-pybind11
python3-pytest
qml-module-qt-labs-folderlistmodel
qml-module-qt-labs-settings
qml-module-qtqml-models2
Expand Down
20 changes: 18 additions & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,25 @@ if (BUILD_TESTING)
testFixture_TEST
)

execute_process(COMMAND "${PYTHON_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}/python/test/${test}.py")
if (pytest_FOUND)
add_test(NAME ${test}.py COMMAND
"${PYTHON_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/python/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/UNIT_${test}.xml")
else()
add_test(NAME ${test}.py COMMAND
"${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/test/${test}.py")
endif()

set(_env_vars)
list(APPEND _env_vars "PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/")
Expand Down

0 comments on commit 199237d

Please sign in to comment.