Skip to content

Conversation

@mhucka
Copy link
Contributor

@mhucka mhucka commented Nov 29, 2025

This provides some slight speedups to Pytest coverage testing by making 2 changes:

  • Add a pytest flag to pyproject.toml to use sys.monitoring if it is available. This can speed up coverage.py. The reason is that sys.monitoring (introduced in Python 3.12 via PEP 669) offers a more efficient way to monitor program execution, potentially leading to faster coverage measurement, especially for line coverage. This feature is only available for Python 3.12+, but it can be turned on always and warnings about not having the sysmon feature can be ignored. Example of a project that found it useful: https://blog.trailofbits.com/2025/05/01/making-pypis-test-suite-81-faster/

  • Change the directories included and excluded to be more selective and get only the directories that have Python test files consumed by Pytest. By changing include and omit values for tool.coverage.run, I get a small but consistent ~5% speedup (on a Linux system when running with -n 32).

As of mid-2025, this feature is available in Python 3.12 and higher, and
is reported to help speed up coverage tests.
@github-actions github-actions bot added the Size: XS <10 lines changed label Nov 29, 2025
@codecov
Copy link

codecov bot commented Nov 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.94%. Comparing base (c6c0eff) to head (03d147e).

❗ There is a different number of reports uploaded between BASE (c6c0eff) and HEAD (03d147e). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (c6c0eff) HEAD (03d147e)
4 2
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7777      +/-   ##
==========================================
- Coverage   99.57%   90.94%   -8.63%     
==========================================
  Files        1102       70    -1032     
  Lines       98425     3590   -94835     
==========================================
- Hits        98006     3265   -94741     
+ Misses        419      325      -94     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

By changing `include` and `omit` values for `tool.coverage.run`, we can
limit the files that pytest-cov scans to look foir tests and thereby
gain a slight speedup. (I'm seeing 5% faster times on a Linux system
when running with `-n 32`.)
@github-actions github-actions bot added size: S 10< lines changed <50 and removed Size: XS <10 lines changed labels Nov 29, 2025
@mhucka mhucka changed the title Add sysmon flag for coverage tests to pyprompt.toml Adjust Python coverage test flags in pyprompt.toml for slight speedup Nov 29, 2025
@mhucka mhucka changed the title Adjust Python coverage test flags in pyprompt.toml for slight speedup Adjust Python coverage test flags in pyprompt.toml for small speed gains Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant