Skip to content

Commit c56c3a2

Browse files
committed
fix: issue a warning if we can't use sysmon as requested.
1 parent 8b0e039 commit c56c3a2

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
Nothing yet.
26+
- Fix: setting ``COVERAGE_CORE=sysmon`` no longer errors on 3.11 and lower,
27+
thanks `Hugo van Kemenade <pull 1747_>`_. It now issues a warning that
28+
sys.monitoring is not available and falls back to the default core instead.
29+
30+
.. _pull 1747: https://github.com/nedbat/coveragepy/pull/1747
2731

2832

2933
.. scriv-start-here

coverage/collector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def __init__(
152152
core = os.getenv("COVERAGE_CORE")
153153

154154
if core == "sysmon" and not env.PYBEHAVIOR.pep669:
155+
self.warn("sys.monitoring isn't available, using default core", slug="no-sysmon")
155156
core = None
156157

157158
if not core:

doc/cmd.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ Conflicting dynamic contexts (dynamic-conflict)
273273
:meth:`.Coverage.switch_context` function to change the context. Only one of
274274
these mechanisms should be in use at a time.
275275

276+
sys.monitoring isn't available, using default core (no-sysmon)
277+
You requested to use the sys.monitoring measurement core, but are running on
278+
Python 3.11 or lower where it isn't available. A default core will be used
279+
instead.
280+
276281
Individual warnings can be disabled with the :ref:`disable_warnings
277282
<config_run_disable_warnings>` configuration setting. To silence "No data was
278283
collected," add this to your configuration file:

tests/test_process.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,13 @@ def test_core_request_sysmon(self) -> None:
11291129
out = self.run_command("coverage run --debug=sys numbers.py")
11301130
assert out.endswith("123 456\n")
11311131
core = re_line(r" core:", out).strip()
1132+
warns = re_lines(r"CoverageWarning: sys.monitoring isn't available", out)
11321133
if env.PYBEHAVIOR.pep669:
11331134
assert core == "core: SysMonitor"
1135+
assert not warns
11341136
else:
11351137
assert core in ("core: CTracer", "core: PyTracer")
1138+
assert warns
11361139

11371140

11381141
class FailUnderNoFilesTest(CoverageTest):

0 commit comments

Comments
 (0)