diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index 93b71a208..2e3da8934 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -572,6 +572,7 @@ function(_create_coverage_targets_impl) ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python --cov-report=term-missing --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml --cov-report=html:${CMAKE_BINARY_DIR}/coverage-python-html + --cov-config=${PROJECT_SOURCE_DIR}/test/python/.coveragerc WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Generating Python coverage report" VERBATIM diff --git a/ci/spack.yaml b/ci/spack.yaml index 17956a10f..c894bbb51 100644 --- a/ci/spack.yaml +++ b/ci/spack.yaml @@ -7,6 +7,7 @@ spack: - ninja - py-gcovr - py-pip # Needed temporarily for ruff installation + - py-pytest-cov # Needed for Python coverage reports - | llvm@21.1.4: +zstd +llvm_dylib +link_llvm_dylib ~lldb targets=x86 diff --git a/test/python/.coveragerc b/test/python/.coveragerc new file mode 100644 index 000000000..e0c6793ab --- /dev/null +++ b/test/python/.coveragerc @@ -0,0 +1,12 @@ +[run] +# Include non-test Python modules for coverage measurement +source = . +omit = + test_*.py + **/test_*.py + +[report] +# Exclude test files from coverage reports +omit = + test_*.py + **/test_*.py diff --git a/test/python/.gitignore b/test/python/.gitignore index 5b8f1e195..ace7b4b33 100644 --- a/test/python/.gitignore +++ b/test/python/.gitignore @@ -1,4 +1,6 @@ __pycache__ +.coverage +.pytest_cache *.pyc *.pyd *.pyo diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 846848abc..c2f73917f 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -64,6 +64,7 @@ if(HAS_CPPYY) --cov-report=term-missing --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml --cov-report=html:${CMAKE_BINARY_DIR}/coverage-python-html + --cov-config=${CMAKE_CURRENT_SOURCE_DIR}/.coveragerc test_phlex.py ) message(STATUS "Python tests will run with coverage reporting (pytest-cov)") diff --git a/test/python/check_sys_path.py b/test/python/check_sys_path.py index f767c4dde..9d7a7acc4 100644 --- a/test/python/check_sys_path.py +++ b/test/python/check_sys_path.py @@ -14,7 +14,7 @@ class Checker: site-packages directory appears in Python's sys.path. """ - __name__ = 'checker' + __name__ = "checker" def __init__(self, venv_path: str): """Initialize the checker with the expected virtual environment path. @@ -36,7 +36,8 @@ def __call__(self, i: int) -> None: """ assert len(sys.path) > 0 venv_site_packages = ( - f"{sys.prefix}/lib/python{sys.version_info.major}.{sys.version_info.minor}/site-packages" + f"{sys.prefix}/lib/python{sys.version_info.major}." + f"{sys.version_info.minor}/site-packages" ) assert any(p == venv_site_packages for p in sys.path) @@ -51,4 +52,4 @@ def PHLEX_REGISTER_ALGORITHMS(m, config): Returns: None """ - m.observe(Checker(config["venv"]), input_family = config["input"]) + m.observe(Checker(config["venv"]), input_family=config["input"])