diff --git a/CHANGES.rst b/CHANGES.rst index 461f2af6c..fd26bc0f6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 `_. 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 diff --git a/coverage/collector.py b/coverage/collector.py index 65e329822..87cd620e3 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -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: diff --git a/doc/cmd.rst b/doc/cmd.rst index a440e987c..439927d9c 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -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 ` configuration setting. To silence "No data was collected," add this to your configuration file: diff --git a/tests/test_process.py b/tests/test_process.py index 8146e0d17..43518066e 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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):