Skip to content

Commit f0e30b9

Browse files
authored
Use sys.monitoring for small speedup of tests in Python 3.12+ (#1220)
This adds 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. The same change was applied in Cirq recently and it has been beneficial there.
1 parent 2bf478a commit f0e30b9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ line-length = 100
1717
target_version = ['py310', 'py311', 'py312', 'py313']
1818
skip-string-normalization = true
1919
skip-magic-trailing-comma = true
20+
21+
[tool.coverage.run]
22+
# Speed up pytest-cov on Python 3.12+ by enabling sys.monitoring if possible.
23+
core = "sysmon"
24+
disable_warnings = ["no-sysmon"]

0 commit comments

Comments
 (0)