Skip to content

Commit 46d6167

Browse files
authored
perf(test): use Python’s system monitoring facilities to improve performance of test runs (#933)
1 parent 6816936 commit 46d6167

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ repos:
160160
hooks:
161161
- id: actionlint
162162

163-
# On push to the remote, run the unit tests.
163+
# On push to the remote, run the unit tests. Note that the `COVERAGE_CORE` variable is
164+
# required for Python 3.12+ to make sure Coverage uses the new Python monitoring module.
165+
# See also: https://blog.trailofbits.com/2025/05/01/making-pypis-test-suite-81-faster/#optimizing-coverage-with-python-312s-sysmonitoring
164166
- repo: local
165167
hooks:
166168
- id: pytest
167169
name: Run unit tests
168-
entry: pytest -c pyproject.toml --cov-config pyproject.toml src/package/ tests/ docs/
170+
entry: env COVERAGE_CORE=sysmon pytest -c pyproject.toml --cov-config pyproject.toml src/package/ tests/ docs/
169171
language: python
170172
verbose: true
171173
always_run: true

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ hooks = [
6161
]
6262
# Note that the `custom_exit_code` and `env` plugins may currently be unmaintained.
6363
test = [
64+
"coverage ==7.6.12; python_version<'3.14'", # https://github.com/pypi/warehouse/pull/17872#issuecomment-2845932281
6465
"faker ==37.6.0",
6566
"hypothesis >=6.21.0,<6.138.17",
6667
"pytest >=7.2.0,<9.0.0",
6768
"pytest-cases ==3.9.1",
6869
"pytest-custom_exit_code ==0.3.0",
69-
"pytest-cov ==7.0.0",
70+
"pytest-cov ==6.3.0", # Uses: coverage[toml] >=7.5
7071
"pytest-doctestplus ==1.4.0",
7172
"pytest-env ==1.1.5",
7273
]
@@ -271,6 +272,11 @@ env = [
271272
filterwarnings = [
272273
"error",
273274
"always::DeprecationWarning",
275+
# The CoverageWarning warning is issued in two contexts:
276+
# Python 3.10, 3.11: sys.monitoring isn't available in this version, using default core (no-sysmon)
277+
# Python 3.12, 3.13: sys.monitoring can't measure branches in this version, using default core (no-sysmon)
278+
"ignore:sys.monitoring isn't available in this version:coverage.exceptions.CoverageWarning",
279+
"always::coverage.exceptions.CoverageWarning",
274280
# https://docs.pytest.org/en/latest/how-to/failures.html#warning-about-unraisable-exceptions-and-unhandled-thread-exceptions
275281
"error::pytest.PytestUnraisableExceptionWarning",
276282
"error::pytest.PytestUnhandledThreadExceptionWarning",

0 commit comments

Comments
 (0)