From a26da031aa830bee204432807cbc34afe50bd5f5 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 24 Aug 2021 11:27:30 -0400 Subject: [PATCH] Use .coveragerc to configure Python coverage reporting --- cmake/.coveragerc.in | 10 ++++++++++ cmake/Modules/CodeCoverage.cmake | 10 ++++++---- unittest/python/CMakeLists.txt | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 cmake/.coveragerc.in diff --git a/cmake/.coveragerc.in b/cmake/.coveragerc.in new file mode 100644 index 0000000000..3dc467d4d0 --- /dev/null +++ b/cmake/.coveragerc.in @@ -0,0 +1,10 @@ +[run] +source = @LAMMPS_PYTHON_DIR@ +parallel=True +branch=True +omit=*/install.py + */setup.py + +[paths] +sources = python + @LAMMPS_PYTHON_DIR@ diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake index 054e08fc1a..21a651e519 100644 --- a/cmake/Modules/CodeCoverage.cmake +++ b/cmake/Modules/CodeCoverage.cmake @@ -54,6 +54,8 @@ if(ENABLE_COVERAGE) if(COVERAGE_FOUND) set(PYTHON_COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/python_coverage_html) + configure_file(.coveragerc.in ${CMAKE_BINARY_DIR}/.coveragerc @ONLY) + add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/unittest/python/.coverage COMMAND ${COVERAGE_BINARY} combine @@ -63,16 +65,16 @@ if(ENABLE_COVERAGE) add_custom_target( gen_python_coverage_html - COMMAND ${COVERAGE_BINARY} html -d ${PYTHON_COVERAGE_HTML_DIR} - DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage + COMMAND ${COVERAGE_BINARY} html --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -d ${PYTHON_COVERAGE_HTML_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python COMMENT "Generating HTML Python coverage report..." ) add_custom_target( gen_python_coverage_xml - COMMAND ${COVERAGE_BINARY} xml -o ${CMAKE_BINARY_DIR}/python_coverage.xml - DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage + COMMAND ${COVERAGE_BINARY} xml --rcfile=${CMAKE_BINARY_DIR}/.coveragerc -o ${CMAKE_BINARY_DIR}/python_coverage.xml + DEPENDS ${CMAKE_BINARY_DIR}/unittest/python/.coverage ${CMAKE_BINARY_DIR}/.coveragerc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/unittest/python COMMENT "Generating XML Python coverage report..." ) diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 6832f7e028..d76f73aceb 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -46,7 +46,7 @@ if(Python_EXECUTABLE) find_package_handle_standard_args(COVERAGE DEFAULT_MSG COVERAGE_BINARY) if(COVERAGE_FOUND) - set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u ${COVERAGE_BINARY} run --parallel-mode --include=${LAMMPS_PYTHON_DIR}/lammps/*.py --omit=${LAMMPS_PYTHON_DIR}/install.py) + set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u ${COVERAGE_BINARY} run --rcfile=${CMAKE_BINARY_DIR}/.coveragerc) else() set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} -u) endif()