Skip to content

Commit

Permalink
fix: issue a warning if we can't use sysmon as requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Feb 20, 2024
1 parent 8b0e039 commit c56c3a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ upgrading your version of coverage.py.
Unreleased
----------

Nothing yet.
- Fix: setting ``COVERAGE_CORE=sysmon`` no longer errors on 3.11 and lower,
thanks `Hugo van Kemenade <pull 1747_>`_. It now issues a warning that
sys.monitoring is not available and falls back to the default core instead.

.. _pull 1747: https://github.com/nedbat/coveragepy/pull/1747


.. scriv-start-here
Expand Down
1 change: 1 addition & 0 deletions coverage/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(
core = os.getenv("COVERAGE_CORE")

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

if not core:
Expand Down
5 changes: 5 additions & 0 deletions doc/cmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ Conflicting dynamic contexts (dynamic-conflict)
:meth:`.Coverage.switch_context` function to change the context. Only one of
these mechanisms should be in use at a time.

sys.monitoring isn't available, using default core (no-sysmon)
You requested to use the sys.monitoring measurement core, but are running on
Python 3.11 or lower where it isn't available. A default core will be used
instead.

Individual warnings can be disabled with the :ref:`disable_warnings
<config_run_disable_warnings>` configuration setting. To silence "No data was
collected," add this to your configuration file:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,13 @@ def test_core_request_sysmon(self) -> None:
out = self.run_command("coverage run --debug=sys numbers.py")
assert out.endswith("123 456\n")
core = re_line(r" core:", out).strip()
warns = re_lines(r"CoverageWarning: sys.monitoring isn't available", out)
if env.PYBEHAVIOR.pep669:
assert core == "core: SysMonitor"
assert not warns
else:
assert core in ("core: CTracer", "core: PyTracer")
assert warns


class FailUnderNoFilesTest(CoverageTest):
Expand Down

0 comments on commit c56c3a2

Please sign in to comment.