Skip to content

Fix Python coverage target environment and availability#318

Merged
knoepfel merged 15 commits intomainfrom
copilot/investigate-test-coverage-issue
Feb 16, 2026
Merged

Fix Python coverage target environment and availability#318
knoepfel merged 15 commits intomainfrom
copilot/investigate-test-coverage-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Fix Python Coverage Target Environment and Availability

Problem

Python coverage monitoring was not properly including plugins/python/python/phlex/__init__.py in reports, and test files were incorrectly included in coverage measurements.

Root Causes

  1. Duplicate targets: Two coverage-python targets were defined, causing conflicts
  2. Missing environment setup: Target wasn't setting PYTHONPATH with Python site-packages
  3. Coverage scope: Tests weren't monitoring the plugins directory
  4. Conditional availability: Target was inside if(HAS_CPPYY) block, causing errors when cppyy unavailable
  5. Test file inclusion: Test utility files were being measured for coverage

Solution

test/python/CMakeLists.txt

  • Add --cov=${PROJECT_SOURCE_DIR}/plugins/python/python to pytest command
  • Move coverage-python target outside HAS_CPPYY block for universal availability
  • Add fallback for when cppyy is not available (runs unit_test_variant.py)
  • Explicitly set environment: PYTHONPATH=${TEST_PYTHONPATH}, PHLEX_INSTALL=${PYTHON_TEST_PHLEX_INSTALL}

Modules/private/CreateCoverageTargets.cmake

  • Remove duplicate coverage-python target
  • Add comment explaining target is defined in test/python/CMakeLists.txt

test/python/.coveragerc

  • Set source to only ../../plugins/python/python (removed . to exclude test dir)
  • Add omit patterns for unit_test_*.py files
  • Add omit patterns for all files in test directories (*/test/*, */tests/*)
  • Ensures test utilities (adder.py, reducer.py, verify.py, etc.) are excluded

COVERAGE_FIX_EXPLANATION.md

  • Remove hardcoded line number references
  • Document duplicate target issue and environment setup requirements
  • Explain TEST_PYTHONPATH components

Result

The coverage-python target now:

  • ✅ Available in all configurations (with or without cppyy)
  • ✅ Uses proper test environment setup
  • ✅ Runs appropriate tests based on available dependencies
  • ✅ Collects coverage ONLY for plugins/python/python/phlex (not test files)
  • ✅ Excludes all test utilities from coverage reports

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Investigate test coverage monitoring for missing Python file Include plugins/python/python in Python coverage scope Feb 13, 2026
Copilot AI requested a review from greenc-FNAL February 13, 2026 14:48
@greenc-FNAL
Copy link
Contributor

@phlexbot format

@github-actions
Copy link
Contributor

Automatic markdownlint fixes pushed (commit 5a70083).
⚠️ Note: Some issues may require manual review and fixing.

@github-actions
Copy link
Contributor

No automatic jsonnetfmt fixes were necessary.

@github-actions
Copy link
Contributor

No automatic clang-format fixes were necessary.

@github-actions
Copy link
Contributor

Automatic cmake-format fixes pushed (commit 45ec36d).
⚠️ Note: Some issues may require manual review and fixing.

@greenc-FNAL greenc-FNAL marked this pull request as ready for review February 13, 2026 14:51
Copilot AI review requested due to automatic review settings February 13, 2026 14:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python coverage configuration so coverage reports include the in-repo phlex Python package under plugins/python/python, not just the test/python directory.

Changes:

  • Add an additional --cov path for plugins/python/python in the pytest invocations used for coverage.
  • Expand .coveragerc source entries to include ../../plugins/python/python.
  • Add a markdown write-up explaining the coverage issue and fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
test/python/CMakeLists.txt Adds --cov=${PROJECT_SOURCE_DIR}/plugins/python/python to the pytest command used when coverage is enabled.
Modules/private/CreateCoverageTargets.cmake Adds the same --cov path to the coverage-python custom target.
test/python/.coveragerc Extends source to include the plugins Python directory.
COVERAGE_FIX_EXPLANATION.md Adds documentation describing the problem and solution.
Comments suppressed due to low confidence (1)

COVERAGE_FIX_EXPLANATION.md:122

  • File ends with an extra blank line; repo text-file rules require exactly one newline at EOF with no trailing blank lines. Remove the trailing empty line at the end of the document.
- __Codecov config__: `codecov.yml` (coverage reporting configuration)

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
+ Coverage   80.19%   80.33%   +0.13%     
==========================================
  Files         126      127       +1     
  Lines        3070     3102      +32     
  Branches      547      547              
==========================================
+ Hits         2462     2492      +30     
- Misses        381      385       +4     
+ Partials      227      225       -2     
Flag Coverage Δ
unittests 80.33% <ø> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d703e4c...9dfc9aa. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title Include plugins/python/python in Python coverage scope Address review feedback: run full test suite in coverage-python target Feb 13, 2026
@greenc-FNAL greenc-FNAL requested a review from Copilot February 13, 2026 15:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@knoepfel
Copy link
Member

@greenc-FNAL, the coverage report indicates that the __init__.py is not imported/used. I would expect that executing the unit_test_variant.py test should record some usage for the __init__.py file. Do you know what's going on?

@greenc-FNAL
Copy link
Contributor

I'll interrogate the SARIF file and see if there's info there. It may not show up until after merge even if it's accounted for though. There's a few things I don't understand about this, yet.

@greenc-FNAL
Copy link
Contributor

@knoepfel I can't re-run workflow from workflow_dispatch due to more conditional bugs (see #324).

@github-actions
Copy link
Contributor

No automatic clang-format fixes were necessary.

@greenc-FNAL
Copy link
Contributor

@copilot https://github.com/Framework-R-D/phlex/actions/runs/22006226496/job/63590495144

The workflows were run from main but the branch checked out was:

Checking out the ref
  /usr/bin/git checkout --progress --force -B copilot/investigate-test-coverage-issue refs/remotes/origin/copilot/investigate-test-coverage-issue
  Switched to a new branch 'copilot/investigate-test-coverage-issue'
  branch 'copilot/investigate-test-coverage-issue' set up to track 'origin/copilot/investigate-test-coverage-issue'.

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>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot https://github.com/Framework-R-D/phlex/actions/runs/22006226496/job/63590495144

The workflows were run from main but the branch checked out was:
...

Found the issue! The coverage-python target was inside the if(HAS_CPPYY) block, so when cppyy wasn't available, the target didn't exist, causing ninja: error: unknown target 'coverage-python'.

Fixed in commit 8292e5e by moving the coverage-python target outside the HAS_CPPYY block with proper fallback:

  • With cppyy: Uses full PYTEST_COMMAND for all Python tests
  • Without cppyy: Runs standalone Python tests (unit_test_variant.py)
  • Both cases: Properly sets PYTHONPATH=${TEST_PYTHONPATH} environment

The target is now always available when HAS_PYTEST_COV AND ENABLE_COVERAGE are true, regardless of cppyy availability.

Copilot AI changed the title Fix Python coverage target environment and duplicate target issue Fix Python coverage target environment and availability Feb 13, 2026
@greenc-FNAL
Copy link
Contributor

@phlexbot format

@github-actions
Copy link
Contributor

No automatic markdownlint fixes were necessary.

@github-actions
Copy link
Contributor

No automatic jsonnetfmt fixes were necessary.

@github-actions
Copy link
Contributor

Automatic cmake-format fixes pushed (commit a6008c3).
⚠️ Note: Some issues may require manual review and fixing.

@github-actions
Copy link
Contributor

No automatic clang-format fixes were necessary.

@greenc-FNAL
Copy link
Contributor

@copilot Successful run this time, but it looks like we're monitoring test files for coverage?

  /__w/phlex/phlex/phlex-src/plugins/python/python/phlex/__init__.py      32      5    84%   19, 23, 85-87
  adder.py                                                                10     10     0%   7-58
  all_config.py                                                           18     18     0%   9-75
  check_sys_path.py                                                       11     11     0%   7-55
  phlexpy.py                                                              16     16     0%   9-43
  reducer.py                                                              14     14     0%   15-81
  sumit.py                                                                 9      9     0%   8-66
  unit_test_variant.py                                                    42      3    93%   54, 69, 78
  vectypes.py                                                             79     79     0%   7-268
  verify.py                                                               23     23     0%   7-87
  verify_extended.py                                                      71     71     0%   4-144

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>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot Successful run this time, but it looks like we're monitoring test files for coverage?

...

Fixed in commit 95a08d1. The issue was that .coveragerc had . (current directory) in the source list, which included all test files.

Changes:

  • 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/*)

Coverage now only measures the actual phlex package code, excluding test utilities like adder.py, reducer.py, verify.py, etc.

@greenc-FNAL
Copy link
Contributor

@phlexbot format

@github-actions
Copy link
Contributor

No automatic markdownlint fixes were necessary.

@github-actions
Copy link
Contributor

No automatic cmake-format fixes were necessary.

@github-actions
Copy link
Contributor

No automatic jsonnetfmt fixes were necessary.

@github-actions
Copy link
Contributor

No automatic clang-format fixes were necessary.

@greenc-FNAL
Copy link
Contributor

@knoepfel This is ready for review/merge.

@greenc-FNAL greenc-FNAL requested a review from knoepfel February 14, 2026 17:38
@knoepfel knoepfel merged commit c2b7fd8 into main Feb 16, 2026
47 checks passed
@knoepfel knoepfel deleted the copilot/investigate-test-coverage-issue branch February 16, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants