From d23108e8eb0ca2fb04e4bc8363b0aeab768bb55a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:46:15 +0000 Subject: [PATCH 01/15] Fix Python coverage to include plugins/python/python directory - Add --cov flag for plugins/python/python in CMakeLists.txt - Update .coveragerc to include plugins directory in source paths - Fixes issue where phlex module was not tracked in coverage Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- Modules/private/CreateCoverageTargets.cmake | 1 + test/python/.coveragerc | 4 +++- test/python/CMakeLists.txt | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index 2e3da8934..c83c8698c 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -570,6 +570,7 @@ function(_create_coverage_targets_impl) ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/test/python PHLEX_INSTALL=${PROJECT_SOURCE_DIR} ${Python_EXECUTABLE} -m pytest ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python + --cov=${PROJECT_SOURCE_DIR}/plugins/python/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 diff --git a/test/python/.coveragerc b/test/python/.coveragerc index e0c6793ab..ee7faf694 100644 --- a/test/python/.coveragerc +++ b/test/python/.coveragerc @@ -1,6 +1,8 @@ [run] # Include non-test Python modules for coverage measurement -source = . +source = + . + ../../plugins/python/python omit = test_*.py **/test_*.py diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 7e97c8167..f9a7bd33b 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -78,6 +78,7 @@ if(HAS_CPPYY) -m pytest --cov=${CMAKE_CURRENT_SOURCE_DIR} + --cov=${PROJECT_SOURCE_DIR}/plugins/python/python --cov-report=term-missing --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml --cov-report=html:${CMAKE_BINARY_DIR}/coverage-python-html From b0e47fbd0b0c3c31225f04dc3ab9921cdb3b3daf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:47:13 +0000 Subject: [PATCH 02/15] Add comprehensive documentation explaining the Python coverage fix Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- COVERAGE_FIX_EXPLANATION.md | 115 ++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 COVERAGE_FIX_EXPLANATION.md diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md new file mode 100644 index 000000000..e891bf68d --- /dev/null +++ b/COVERAGE_FIX_EXPLANATION.md @@ -0,0 +1,115 @@ +# Python Coverage Fix: Including plugins/python/python/phlex/__init__.py + +## Problem Statement + +The file `plugins/python/python/phlex/__init__.py` was not appearing in Python test coverage reports, despite being imported and used by the test suite (specifically by `test/python/unit_test_variant.py`). + +## Root Cause Analysis + +The Python coverage configuration was only monitoring the test directory itself, not the actual source code being tested: + +1. **In `test/python/CMakeLists.txt`** (lines 74-87): + - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers `/home/runner/work/phlex/phlex/test/python` + - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` + +2. **In `Modules/private/CreateCoverageTargets.cmake`** (lines 564-579): + - The `coverage-python` target had the same limitation + - Only monitored `${PROJECT_SOURCE_DIR}/test/python` + +3. **In `test/python/.coveragerc`**: + - The `source` setting only included `.` (the current test directory) + - Did not include the path to the plugins directory + +## The Fix + +### Changes Made + +1. **test/python/CMakeLists.txt** (line 81): + ```cmake + --cov=${CMAKE_CURRENT_SOURCE_DIR} + --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line + ``` + +2. **Modules/private/CreateCoverageTargets.cmake** (line 573): + ```cmake + ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python + --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line + ``` + +3. **test/python/.coveragerc** (lines 3-5): + ```ini + [run] + source = + . + ../../plugins/python/python # Added this line + ``` + +## How pytest-cov Works + +pytest-cov uses the `--cov` flag to specify which directories/packages to monitor for coverage: + +- Multiple `--cov` flags can be specified to monitor multiple locations +- Each `--cov` flag adds a path to the coverage measurement scope +- The `.coveragerc` file's `source` setting works in conjunction with the `--cov` flags + +## Testing the Fix + +To verify this fix works: + +1. **Build with coverage enabled**: + ```bash + cd /home/runner/work/phlex/phlex + . scripts/setup-env.sh + cmake --preset coverage-clang # or coverage-gcc + ninja -C build + ``` + +2. **Run Python tests with coverage**: + ```bash + cd build + cmake --build . --target coverage-python + ``` + +3. **Check the coverage report**: + ```bash + # View the XML report + grep "plugins/python/python/phlex/__init__.py" coverage-python.xml + + # Or view the HTML report + xdg-open coverage-python-html/index.html + ``` + +4. **Expected Result**: + - The file `plugins/python/python/phlex/__init__.py` should now appear in coverage reports + - Coverage metrics should show which lines of the `Variant` class are executed during tests + +## Why This Matters + +The `phlex` Python package provides the `Variant` class, which is essential for: + +- Wrapping Python callables with custom type annotations +- Allowing the same function to be registered multiple times with different types +- Supporting C++ template-like behavior in Python code + +Without proper coverage tracking, we couldn't verify that: + +- All code paths in the `Variant` class are tested +- Error handling works correctly +- Edge cases are covered + +## Verification in CI + +The GitHub Actions workflow (`.github/workflows/coverage.yaml`) will now: + +1. Run tests with coverage collection including the plugins directory (line 227-250) +2. Generate `coverage-python.xml` with the plugins included +3. Upload to Codecov with both C++ and Python coverage data (line 386-396) + +The `codecov.yml` configuration doesn't explicitly ignore the `plugins` directory, so the data will be properly processed and displayed in coverage reports. + +## Related Files + +- **Test file using the module**: `test/python/unit_test_variant.py` (imports `from phlex import Variant`) +- **Source module**: `plugins/python/python/phlex/__init__.py` (contains the `Variant` class) +- **Coverage workflow**: `.github/workflows/coverage.yaml` (CI coverage execution) +- **Codecov config**: `codecov.yml` (coverage reporting configuration) From 3e131e4d079ed8304c0b2de222402543086b7f2a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:51:11 +0000 Subject: [PATCH 03/15] Apply markdownlint fixes --- COVERAGE_FIX_EXPLANATION.md | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index e891bf68d..643b28ebd 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -8,15 +8,15 @@ The file `plugins/python/python/phlex/__init__.py` was not appearing in Python t The Python coverage configuration was only monitoring the test directory itself, not the actual source code being tested: -1. **In `test/python/CMakeLists.txt`** (lines 74-87): +1. __In `test/python/CMakeLists.txt`__ (lines 74-87): - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers `/home/runner/work/phlex/phlex/test/python` - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` -2. **In `Modules/private/CreateCoverageTargets.cmake`** (lines 564-579): +2. __In `Modules/private/CreateCoverageTargets.cmake`__ (lines 564-579): - The `coverage-python` target had the same limitation - Only monitored `${PROJECT_SOURCE_DIR}/test/python` -3. **In `test/python/.coveragerc`**: +3. __In `test/python/.coveragerc`__: - The `source` setting only included `.` (the current test directory) - Did not include the path to the plugins directory @@ -24,19 +24,22 @@ The Python coverage configuration was only monitoring the test directory itself, ### Changes Made -1. **test/python/CMakeLists.txt** (line 81): +1. __test/python/CMakeLists.txt__ (line 81): + ```cmake --cov=${CMAKE_CURRENT_SOURCE_DIR} --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` -2. **Modules/private/CreateCoverageTargets.cmake** (line 573): +2. __Modules/private/CreateCoverageTargets.cmake__ (line 573): + ```cmake ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` -3. **test/python/.coveragerc** (lines 3-5): +3. __test/python/.coveragerc__ (lines 3-5): + ```ini [run] source = @@ -56,7 +59,8 @@ pytest-cov uses the `--cov` flag to specify which directories/packages to monito To verify this fix works: -1. **Build with coverage enabled**: +1. __Build with coverage enabled__: + ```bash cd /home/runner/work/phlex/phlex . scripts/setup-env.sh @@ -64,13 +68,15 @@ To verify this fix works: ninja -C build ``` -2. **Run Python tests with coverage**: +2. __Run Python tests with coverage__: + ```bash cd build cmake --build . --target coverage-python ``` -3. **Check the coverage report**: +3. __Check the coverage report__: + ```bash # View the XML report grep "plugins/python/python/phlex/__init__.py" coverage-python.xml @@ -79,7 +85,7 @@ To verify this fix works: xdg-open coverage-python-html/index.html ``` -4. **Expected Result**: +4. __Expected Result__: - The file `plugins/python/python/phlex/__init__.py` should now appear in coverage reports - Coverage metrics should show which lines of the `Variant` class are executed during tests @@ -109,7 +115,7 @@ The `codecov.yml` configuration doesn't explicitly ignore the `plugins` director ## Related Files -- **Test file using the module**: `test/python/unit_test_variant.py` (imports `from phlex import Variant`) -- **Source module**: `plugins/python/python/phlex/__init__.py` (contains the `Variant` class) -- **Coverage workflow**: `.github/workflows/coverage.yaml` (CI coverage execution) -- **Codecov config**: `codecov.yml` (coverage reporting configuration) +- __Test file using the module__: `test/python/unit_test_variant.py` (imports `from phlex import Variant`) +- __Source module__: `plugins/python/python/phlex/__init__.py` (contains the `Variant` class) +- __Coverage workflow__: `.github/workflows/coverage.yaml` (CI coverage execution) +- __Codecov config__: `codecov.yml` (coverage reporting configuration) From de5c79025e5b148dff828d7bb275996fd411bc95 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 14:51:13 +0000 Subject: [PATCH 04/15] Apply cmake-format fixes --- Modules/private/CreateCoverageTargets.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index c83c8698c..a6a571b4e 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -570,8 +570,8 @@ function(_create_coverage_targets_impl) ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/test/python PHLEX_INSTALL=${PROJECT_SOURCE_DIR} ${Python_EXECUTABLE} -m pytest ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python - --cov=${PROJECT_SOURCE_DIR}/plugins/python/python - --cov-report=term-missing --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml + --cov=${PROJECT_SOURCE_DIR}/plugins/python/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} From 7b17195bf5aa4d7e7173fa026c5d69fd952acefa Mon Sep 17 00:00:00 2001 From: Chris Green Date: Fri, 13 Feb 2026 09:06:34 -0600 Subject: [PATCH 05/15] Remove hard-wired path Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- COVERAGE_FIX_EXPLANATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index 643b28ebd..44fbe0848 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -9,7 +9,7 @@ The file `plugins/python/python/phlex/__init__.py` was not appearing in Python t The Python coverage configuration was only monitoring the test directory itself, not the actual source code being tested: 1. __In `test/python/CMakeLists.txt`__ (lines 74-87): - - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers `/home/runner/work/phlex/phlex/test/python` + - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers the `test/python` directory within the project source tree (for example, `${PROJECT_SOURCE_DIR}/test/python`) - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` 2. __In `Modules/private/CreateCoverageTargets.cmake`__ (lines 564-579): From 7d247d68540b017af8f902cd55f7e6c9611acab4 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Fri, 13 Feb 2026 09:06:54 -0600 Subject: [PATCH 06/15] Remove unwanted whitespace Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/python/.coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/python/.coveragerc b/test/python/.coveragerc index ee7faf694..57bc3ca93 100644 --- a/test/python/.coveragerc +++ b/test/python/.coveragerc @@ -1,6 +1,6 @@ [run] # Include non-test Python modules for coverage measurement -source = +source = . ../../plugins/python/python omit = From f01476b1db7abc69e45ef5498859adc4dc52292d Mon Sep 17 00:00:00 2001 From: Chris Green Date: Fri, 13 Feb 2026 09:08:19 -0600 Subject: [PATCH 07/15] Minor whitespace fix --- COVERAGE_FIX_EXPLANATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index 44fbe0848..0d249776b 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -80,7 +80,7 @@ To verify this fix works: ```bash # View the XML report grep "plugins/python/python/phlex/__init__.py" coverage-python.xml - + # Or view the HTML report xdg-open coverage-python-html/index.html ``` From 0fb3312d7e7677ca1ac2a01997cd21979b60102f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:32:27 +0000 Subject: [PATCH 08/15] Address unresolved review comments - Update CreateCoverageTargets.cmake to run full test directory (not just test_phlex.py) - Add plugins/python/python to PYTHONPATH in coverage-python target - Remove specific line number references from COVERAGE_FIX_EXPLANATION.md - Update documentation to reflect running full test directory Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- COVERAGE_FIX_EXPLANATION.md | 20 +++++++++++--------- Modules/private/CreateCoverageTargets.cmake | 5 +++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index 0d249776b..16e0fcc06 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -8,11 +8,11 @@ The file `plugins/python/python/phlex/__init__.py` was not appearing in Python t The Python coverage configuration was only monitoring the test directory itself, not the actual source code being tested: -1. __In `test/python/CMakeLists.txt`__ (lines 74-87): +1. __In `test/python/CMakeLists.txt`__: - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers the `test/python` directory within the project source tree (for example, `${PROJECT_SOURCE_DIR}/test/python`) - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` -2. __In `Modules/private/CreateCoverageTargets.cmake`__ (lines 564-579): +2. __In `Modules/private/CreateCoverageTargets.cmake`__: - The `coverage-python` target had the same limitation - Only monitored `${PROJECT_SOURCE_DIR}/test/python` @@ -24,25 +24,27 @@ The Python coverage configuration was only monitoring the test directory itself, ### Changes Made -1. __test/python/CMakeLists.txt__ (line 81): +1. __test/python/CMakeLists.txt__: ```cmake --cov=${CMAKE_CURRENT_SOURCE_DIR} --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` -2. __Modules/private/CreateCoverageTargets.cmake__ (line 573): +2. __Modules/private/CreateCoverageTargets.cmake__: ```cmake - ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python + ${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` -3. __test/python/.coveragerc__ (lines 3-5): + Also updated to run the full test directory and include plugins/python/python in PYTHONPATH. + +3. __test/python/.coveragerc__: ```ini [run] - source = + source = . ../../plugins/python/python # Added this line ``` @@ -107,9 +109,9 @@ Without proper coverage tracking, we couldn't verify that: The GitHub Actions workflow (`.github/workflows/coverage.yaml`) will now: -1. Run tests with coverage collection including the plugins directory (line 227-250) +1. Run tests with coverage collection including the plugins directory 2. Generate `coverage-python.xml` with the plugins included -3. Upload to Codecov with both C++ and Python coverage data (line 386-396) +3. Upload to Codecov with both C++ and Python coverage data The `codecov.yml` configuration doesn't explicitly ignore the `plugins` directory, so the data will be properly processed and displayed in coverage reports. diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index a6a571b4e..a43ee8638 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -567,9 +567,10 @@ function(_create_coverage_targets_impl) ${CMAKE_COMMAND} -E echo "[Coverage] Generating Python coverage report using pytest-cov..." COMMAND - ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/test/python + ${CMAKE_COMMAND} -E env + PYTHONPATH=${PROJECT_SOURCE_DIR}/test/python:${PROJECT_SOURCE_DIR}/plugins/python/python PHLEX_INSTALL=${PROJECT_SOURCE_DIR} ${Python_EXECUTABLE} -m pytest - ${PROJECT_SOURCE_DIR}/test/python/test_phlex.py --cov=${PROJECT_SOURCE_DIR}/test/python + ${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/plugins/python/python --cov-report=term-missing --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml --cov-report=html:${CMAKE_BINARY_DIR}/coverage-python-html From 6c6a73875c84a7ad2adcfc223dab2a5d7b443392 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 22:43:41 +0000 Subject: [PATCH 09/15] Fix duplicate coverage-python target and environment setup - Remove duplicate coverage-python target from CreateCoverageTargets.cmake - Use the properly configured target in test/python/CMakeLists.txt - Add explicit PYTHONPATH and PHLEX_INSTALL to coverage-python target - This ensures tests run with correct environment including Python site-packages Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- Modules/private/CreateCoverageTargets.cmake | 37 ++------------------- test/python/CMakeLists.txt | 4 ++- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index a43ee8638..8ed970e7f 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -552,41 +552,8 @@ function(_create_coverage_targets_impl) COMMENT "Cleaning coverage data files (C++ and Python)" ) - # Add Python coverage target if pytest-cov is available - if(Python_FOUND) - execute_process( - COMMAND ${Python_EXECUTABLE} -c "import pytest_cov" - RESULT_VARIABLE PYTEST_COV_CHECK - OUTPUT_QUIET - ERROR_QUIET - ) - if(PYTEST_COV_CHECK EQUAL 0) - add_custom_target( - coverage-python - COMMAND - ${CMAKE_COMMAND} -E echo - "[Coverage] Generating Python coverage report using pytest-cov..." - COMMAND - ${CMAKE_COMMAND} -E env - PYTHONPATH=${PROJECT_SOURCE_DIR}/test/python:${PROJECT_SOURCE_DIR}/plugins/python/python - PHLEX_INSTALL=${PROJECT_SOURCE_DIR} ${Python_EXECUTABLE} -m pytest - ${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/test/python - --cov=${PROJECT_SOURCE_DIR}/plugins/python/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 - ) - message(STATUS "Added 'coverage-python' target for Python test coverage (pytest-cov)") - else() - message( - STATUS - "pytest-cov not found; Python coverage target not available. Install with: pip install pytest-cov" - ) - endif() - endif() + # Note: The coverage-python target is defined in test/python/CMakeLists.txt + # where it can use the proper test environment setup (PYTHONPATH, etc.) message( STATUS diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index f9a7bd33b..00954246a 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -101,7 +101,9 @@ if(HAS_CPPYY) if(HAS_PYTEST_COV) add_custom_target( coverage-python - COMMAND ${PYTEST_COMMAND} + COMMAND + ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} + PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL} ${PYTEST_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running Python coverage report" ) From edbdc0658e794cf9ef1a077b42938a7b6a17a657 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 22:44:42 +0000 Subject: [PATCH 10/15] Update documentation to explain environment setup fix - Explain the duplicate target issue - Document TEST_PYTHONPATH and its components - Clarify why environment variables are needed for coverage tests Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- COVERAGE_FIX_EXPLANATION.md | 54 ++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index 16e0fcc06..9b04e9098 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -6,17 +6,23 @@ The file `plugins/python/python/phlex/__init__.py` was not appearing in Python t ## Root Cause Analysis -The Python coverage configuration was only monitoring the test directory itself, not the actual source code being tested: +The Python coverage configuration had multiple issues: -1. __In `test/python/CMakeLists.txt`__: - - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers the `test/python` directory within the project source tree (for example, `${PROJECT_SOURCE_DIR}/test/python`) +1. __Coverage Scope__ - Only monitoring the test directory: + - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers the `test/python` directory - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` -2. __In `Modules/private/CreateCoverageTargets.cmake`__: - - The `coverage-python` target had the same limitation - - Only monitored `${PROJECT_SOURCE_DIR}/test/python` +2. __Duplicate Targets__ - Two `coverage-python` targets were defined: + - One in `test/python/CMakeLists.txt` (correctly configured with test environment) + - One in `Modules/private/CreateCoverageTargets.cmake` (duplicate, missing proper environment) + - The duplicate was overriding the correct one -3. __In `test/python/.coveragerc`__: +3. __Environment Setup__ - Tests require proper PYTHONPATH: + - Need test directory, plugins directory, Python site-packages + - The `coverage-python` target wasn't explicitly setting environment variables + - Tests failed because they couldn't import required modules (cppyy, numpy, etc.) + +4. __In `test/python/.coveragerc`__: - The `source` setting only included `.` (the current test directory) - Did not include the path to the plugins directory @@ -26,19 +32,27 @@ The Python coverage configuration was only monitoring the test directory itself, 1. __test/python/CMakeLists.txt__: + Added `--cov` flag for the plugins directory: ```cmake --cov=${CMAKE_CURRENT_SOURCE_DIR} --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` -2. __Modules/private/CreateCoverageTargets.cmake__: - + Updated `coverage-python` target to use proper test environment: ```cmake - ${PROJECT_SOURCE_DIR}/test/python --cov=${PROJECT_SOURCE_DIR}/test/python - --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line + add_custom_target( + coverage-python + COMMAND + ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} + PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL} ${PYTEST_COMMAND} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running Python coverage report" + ) ``` - Also updated to run the full test directory and include plugins/python/python in PYTHONPATH. +2. __Modules/private/CreateCoverageTargets.cmake__: + + Removed the duplicate `coverage-python` target that was conflicting with the properly configured one in `test/python/CMakeLists.txt`. 3. __test/python/.coveragerc__: @@ -57,6 +71,22 @@ pytest-cov uses the `--cov` flag to specify which directories/packages to monito - Each `--cov` flag adds a path to the coverage measurement scope - The `.coveragerc` file's `source` setting works in conjunction with the `--cov` flags +## Environment Setup + +The `TEST_PYTHONPATH` variable in `test/python/CMakeLists.txt` includes: + +- `${CMAKE_CURRENT_SOURCE_DIR}` - the test directory +- `${PROJECT_SOURCE_DIR}/plugins/python/python` - the phlex package source +- `${Python_SITELIB}` and `${Python_SITEARCH}` - Python site-packages (for cppyy, numpy, etc.) +- `$ENV{PYTHONPATH}` - any existing PYTHONPATH from the environment + +This comprehensive PYTHONPATH is required for tests to: +1. Import the `phlex` module from `plugins/python/python/phlex/__init__.py` +2. Import test dependencies like `cppyy`, `numpy`, `pytest` +3. Find any user-installed packages + +The `coverage-python` target explicitly sets these environment variables so that the coverage run has the same environment as the regular test run. + ## Testing the Fix To verify this fix works: From a6d91cd13974485cd32bfec9b1acc06581441eea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 23:19:24 +0000 Subject: [PATCH 11/15] Apply markdownlint fixes --- COVERAGE_FIX_EXPLANATION.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md index 9b04e9098..ce4f9727c 100644 --- a/COVERAGE_FIX_EXPLANATION.md +++ b/COVERAGE_FIX_EXPLANATION.md @@ -33,12 +33,14 @@ The Python coverage configuration had multiple issues: 1. __test/python/CMakeLists.txt__: Added `--cov` flag for the plugins directory: + ```cmake --cov=${CMAKE_CURRENT_SOURCE_DIR} --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line ``` Updated `coverage-python` target to use proper test environment: + ```cmake add_custom_target( coverage-python @@ -81,6 +83,7 @@ The `TEST_PYTHONPATH` variable in `test/python/CMakeLists.txt` includes: - `$ENV{PYTHONPATH}` - any existing PYTHONPATH from the environment This comprehensive PYTHONPATH is required for tests to: + 1. Import the `phlex` module from `plugins/python/python/phlex/__init__.py` 2. Import test dependencies like `cppyy`, `numpy`, `pytest` 3. Find any user-installed packages From 8292e5ecb815e38498cf7e653a155ef829b50444 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 23:35:09 +0000 Subject: [PATCH 12/15] Move coverage-python target outside HAS_CPPYY block The coverage-python target was inside the if(HAS_CPPYY) block, causing "ninja: error: unknown target 'coverage-python'" when cppyy is not available. Moved the target definition to after all environment setup (TEST_PYTHONPATH, PYTHON_TEST_ENVIRONMENT) so it's always available when pytest-cov is installed. Added fallback for when cppyy is not available: - Uses simpler pytest command for standalone Python tests - Runs unit_test_variant.py to test the phlex Python package - Still collects coverage for both test and plugins directories This ensures the coverage-python target exists regardless of cppyy availability. Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- test/python/CMakeLists.txt | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 00954246a..c8bbe2f8b 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -97,17 +97,6 @@ if(HAS_CPPYY) add_test(NAME py:phlex COMMAND ${PYTEST_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set_property(TEST py:phlex PROPERTY ENVIRONMENT "PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL}") - - if(HAS_PYTEST_COV) - add_custom_target( - coverage-python - COMMAND - ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} - PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL} ${PYTEST_COMMAND} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Running Python coverage report" - ) - endif() endif() set(ACTIVE_PY_CPHLEX_TESTS "") @@ -264,3 +253,38 @@ add_test( COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/unit_test_variant.py ) set_tests_properties(py:unit_variant PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + +# Python coverage target +if(HAS_PYTEST_COV AND ENABLE_COVERAGE) + if(HAS_CPPYY) + # When cppyy is available, use the full pytest command + add_custom_target( + coverage-python + COMMAND + ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} + PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL} ${PYTEST_COMMAND} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running Python coverage report" + ) + else() + # When cppyy is not available, run a simpler pytest command + # for standalone Python tests (like unit_test_variant.py) + set(PYTHON_TEST_PHLEX_INSTALL_FALLBACK ${CMAKE_SOURCE_DIR}) + add_custom_target( + coverage-python + COMMAND + ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} + PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL_FALLBACK} ${Python_EXECUTABLE} + -m pytest + --cov=${CMAKE_CURRENT_SOURCE_DIR} + --cov=${PROJECT_SOURCE_DIR}/plugins/python/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=${CMAKE_CURRENT_SOURCE_DIR}/.coveragerc + unit_test_variant.py + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running Python coverage report (standalone tests only)" + ) + endif() +endif() From a6008c3471dcf9386082cfb3815a6f47b237509e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 23:38:48 +0000 Subject: [PATCH 13/15] Apply cmake-format fixes --- test/python/CMakeLists.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index c8bbe2f8b..2ce3629ad 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -274,15 +274,11 @@ if(HAS_PYTEST_COV AND ENABLE_COVERAGE) coverage-python COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} - PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL_FALLBACK} ${Python_EXECUTABLE} - -m pytest - --cov=${CMAKE_CURRENT_SOURCE_DIR} - --cov=${PROJECT_SOURCE_DIR}/plugins/python/python - --cov-report=term-missing - --cov-report=xml:${CMAKE_BINARY_DIR}/coverage-python.xml + PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL_FALLBACK} ${Python_EXECUTABLE} -m pytest + --cov=${CMAKE_CURRENT_SOURCE_DIR} --cov=${PROJECT_SOURCE_DIR}/plugins/python/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=${CMAKE_CURRENT_SOURCE_DIR}/.coveragerc - unit_test_variant.py + --cov-config=${CMAKE_CURRENT_SOURCE_DIR}/.coveragerc unit_test_variant.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running Python coverage report (standalone tests only)" ) From 95a08d18cfc6977052aeb2760bc7b08767ffe0b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 23:52:30 +0000 Subject: [PATCH 14/15] Exclude test files from Python coverage reports Updated .coveragerc to properly exclude all test files from coverage: - Removed '.' from source list (only measure plugins/python/python) - Added omit patterns for unit_test_*.py files - Added omit patterns for all files in test directories (*/test/*, */tests/*) This ensures only the actual phlex package code is measured, not test utilities like adder.py, reducer.py, verify.py, vectypes.py, etc. Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com> --- test/python/.coveragerc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/python/.coveragerc b/test/python/.coveragerc index 57bc3ca93..7eedeba1d 100644 --- a/test/python/.coveragerc +++ b/test/python/.coveragerc @@ -1,14 +1,23 @@ [run] # Include non-test Python modules for coverage measurement source = - . ../../plugins/python/python omit = test_*.py **/test_*.py + unit_test_*.py + **/unit_test_*.py + # Omit all files in test directories + */test/* + */tests/* [report] # Exclude test files from coverage reports omit = test_*.py **/test_*.py + unit_test_*.py + **/unit_test_*.py + # Omit all files in test directories + */test/* + */tests/* From 9dfc9aae753c7f2467911128ca1023f7bc158141 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Sat, 14 Feb 2026 10:00:56 -0600 Subject: [PATCH 15/15] Remove unneeded file per https://github.com/Framework-R-D/phlex/pull/318#discussion_r2807563063 --- COVERAGE_FIX_EXPLANATION.md | 156 ------------------------------------ 1 file changed, 156 deletions(-) delete mode 100644 COVERAGE_FIX_EXPLANATION.md diff --git a/COVERAGE_FIX_EXPLANATION.md b/COVERAGE_FIX_EXPLANATION.md deleted file mode 100644 index ce4f9727c..000000000 --- a/COVERAGE_FIX_EXPLANATION.md +++ /dev/null @@ -1,156 +0,0 @@ -# Python Coverage Fix: Including plugins/python/python/phlex/__init__.py - -## Problem Statement - -The file `plugins/python/python/phlex/__init__.py` was not appearing in Python test coverage reports, despite being imported and used by the test suite (specifically by `test/python/unit_test_variant.py`). - -## Root Cause Analysis - -The Python coverage configuration had multiple issues: - -1. __Coverage Scope__ - Only monitoring the test directory: - - The pytest command used `--cov=${CMAKE_CURRENT_SOURCE_DIR}` which only covers the `test/python` directory - - Missing: Coverage for the `phlex` module located in `plugins/python/python/phlex/` - -2. __Duplicate Targets__ - Two `coverage-python` targets were defined: - - One in `test/python/CMakeLists.txt` (correctly configured with test environment) - - One in `Modules/private/CreateCoverageTargets.cmake` (duplicate, missing proper environment) - - The duplicate was overriding the correct one - -3. __Environment Setup__ - Tests require proper PYTHONPATH: - - Need test directory, plugins directory, Python site-packages - - The `coverage-python` target wasn't explicitly setting environment variables - - Tests failed because they couldn't import required modules (cppyy, numpy, etc.) - -4. __In `test/python/.coveragerc`__: - - The `source` setting only included `.` (the current test directory) - - Did not include the path to the plugins directory - -## The Fix - -### Changes Made - -1. __test/python/CMakeLists.txt__: - - Added `--cov` flag for the plugins directory: - - ```cmake - --cov=${CMAKE_CURRENT_SOURCE_DIR} - --cov=${PROJECT_SOURCE_DIR}/plugins/python/python # Added this line - ``` - - Updated `coverage-python` target to use proper test environment: - - ```cmake - add_custom_target( - coverage-python - COMMAND - ${CMAKE_COMMAND} -E env PYTHONPATH=${TEST_PYTHONPATH} - PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL} ${PYTEST_COMMAND} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Running Python coverage report" - ) - ``` - -2. __Modules/private/CreateCoverageTargets.cmake__: - - Removed the duplicate `coverage-python` target that was conflicting with the properly configured one in `test/python/CMakeLists.txt`. - -3. __test/python/.coveragerc__: - - ```ini - [run] - source = - . - ../../plugins/python/python # Added this line - ``` - -## How pytest-cov Works - -pytest-cov uses the `--cov` flag to specify which directories/packages to monitor for coverage: - -- Multiple `--cov` flags can be specified to monitor multiple locations -- Each `--cov` flag adds a path to the coverage measurement scope -- The `.coveragerc` file's `source` setting works in conjunction with the `--cov` flags - -## Environment Setup - -The `TEST_PYTHONPATH` variable in `test/python/CMakeLists.txt` includes: - -- `${CMAKE_CURRENT_SOURCE_DIR}` - the test directory -- `${PROJECT_SOURCE_DIR}/plugins/python/python` - the phlex package source -- `${Python_SITELIB}` and `${Python_SITEARCH}` - Python site-packages (for cppyy, numpy, etc.) -- `$ENV{PYTHONPATH}` - any existing PYTHONPATH from the environment - -This comprehensive PYTHONPATH is required for tests to: - -1. Import the `phlex` module from `plugins/python/python/phlex/__init__.py` -2. Import test dependencies like `cppyy`, `numpy`, `pytest` -3. Find any user-installed packages - -The `coverage-python` target explicitly sets these environment variables so that the coverage run has the same environment as the regular test run. - -## Testing the Fix - -To verify this fix works: - -1. __Build with coverage enabled__: - - ```bash - cd /home/runner/work/phlex/phlex - . scripts/setup-env.sh - cmake --preset coverage-clang # or coverage-gcc - ninja -C build - ``` - -2. __Run Python tests with coverage__: - - ```bash - cd build - cmake --build . --target coverage-python - ``` - -3. __Check the coverage report__: - - ```bash - # View the XML report - grep "plugins/python/python/phlex/__init__.py" coverage-python.xml - - # Or view the HTML report - xdg-open coverage-python-html/index.html - ``` - -4. __Expected Result__: - - The file `plugins/python/python/phlex/__init__.py` should now appear in coverage reports - - Coverage metrics should show which lines of the `Variant` class are executed during tests - -## Why This Matters - -The `phlex` Python package provides the `Variant` class, which is essential for: - -- Wrapping Python callables with custom type annotations -- Allowing the same function to be registered multiple times with different types -- Supporting C++ template-like behavior in Python code - -Without proper coverage tracking, we couldn't verify that: - -- All code paths in the `Variant` class are tested -- Error handling works correctly -- Edge cases are covered - -## Verification in CI - -The GitHub Actions workflow (`.github/workflows/coverage.yaml`) will now: - -1. Run tests with coverage collection including the plugins directory -2. Generate `coverage-python.xml` with the plugins included -3. Upload to Codecov with both C++ and Python coverage data - -The `codecov.yml` configuration doesn't explicitly ignore the `plugins` directory, so the data will be properly processed and displayed in coverage reports. - -## Related Files - -- __Test file using the module__: `test/python/unit_test_variant.py` (imports `from phlex import Variant`) -- __Source module__: `plugins/python/python/phlex/__init__.py` (contains the `Variant` class) -- __Coverage workflow__: `.github/workflows/coverage.yaml` (CI coverage execution) -- __Codecov config__: `codecov.yml` (coverage reporting configuration)