Skip to content

Warn when sysmon cannot switch dynamic contexts - #2234

Merged
nedbat merged 8 commits into
coveragepy:mainfrom
JSap0914:warn-sysmon-switch-context-2200
Jul 27, 2026
Merged

nedbat merged 8 commits into
coveragepy:mainfrom
JSap0914:warn-sysmon-switch-context-2200

Conversation

@JSap0914

Copy link
Copy Markdown
Contributor

What

Add an explicit core capability for dynamic contexts and warn once when switch_context() is used with the sys.monitoring core.

Why

The sysmon core cannot currently honor dynamic context switches. Programmatic calls previously continued silently, which could produce incomplete per-context data without any indication to the caller.

Fixes #2200

Tests

  • COVERAGE_CORE=sysmon python -m pytest -q tests/test_api.py::ApiTest::test_switch_context_sysmon_warning
  • COVERAGE_CORE=ctrace python -m pytest -q tests/test_api.py::SwitchContextTest
  • COVERAGE_CORE=pytrace python -m pytest -q tests/test_api.py::SwitchContextTest
  • HYPOTHESIS_PROFILE=ci tox -q -e py314
  • python -m mypy --python-version=3.14 --strict coverage tests setup.py
  • ruff format --check coverage/control.py coverage/core.py tests/test_api.py
  • python -m pylint --notes= coverage/control.py coverage/core.py tests/test_api.py
  • pre-commit run --files coverage/control.py coverage/core.py tests/test_api.py

@nedbat
nedbat merged commit 153ebe6 into coveragepy:main Jul 27, 2026
71 checks passed
@nedbat

nedbat commented Aug 2, 2026

Copy link
Copy Markdown
Member

This is now released as part of coverage 7.15.3.

@webknjaz

webknjaz commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

xref also mentioned in the pytest plugin where the warning leaks with insufficient context as is: pytest-dev/pytest-cov#755


Search string for people from search engines:

Dynamic contexts aren't supported with core=sysmon; context data may be incomplete (no-sysmon-context); see https://coverage.readthedocs.io/en/7.15.3/messages.html#warning-no-sysmon-context

webknjaz added a commit to re-actors/alls-green that referenced this pull request Aug 21, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234
webknjaz added a commit to ansible/awx_plugins.interfaces that referenced this pull request Sep 14, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Signed-off-by: Sviatoslav Sydorenko <[email protected]>
github-actions Bot added a commit to step-security/alls-green that referenced this pull request Sep 24, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234
Raj-StepSecurity pushed a commit to step-security/alls-green that referenced this pull request Sep 24, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234
webknjaz added a commit to tox-dev/tox-pre-commit that referenced this pull request Oct 2, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Signed-off-by: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit to ansible/awx-plugins that referenced this pull request Nov 1, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Signed-off-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit 23e7f40d528fdc3a981888fed407d499a77613f2)
webknjaz added a commit to ansible/awx-plugins that referenced this pull request Nov 1, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
*
https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234


(cherry picked from commit 23e7f40d528fdc3a981888fed407d499a77613f2 @
ansible/awx_plugins.interfaces#50)
webknjaz added a commit to tox-dev/tox-towncrier that referenced this pull request Nov 14, 2026
This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started
emitting and our configuration is turning into hard errors. The
setting is ported from tox-pre-commit, whose .coveragerc this one
now matches.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Assisted-by: LLM
webknjaz added a commit to webknjaz/tox-dev--tox-build that referenced this pull request Nov 14, 2026
Coverage runs under the covdefaults plugin (sensible exclusion
defaults for branch coverage, ignored boilerplate, common
optional-imports patterns).

Two additional `exclude_also` entries beyond covdefaults: the
`@pytest.mark.xfail` decorator pattern, and the project-local
`if _t.TYPE_CHECKING:` form. The header comment references
coverage's and covdefaults' canonical exclusion lists so the
deltas are easy to audit later (the comment shape comes from
jazzband/pip-tools).

The `[paths]` section maps multi-layout site-packages locations
(`src/` next to `*/src` for tox envs, posix `lib/python*` next to
pypy and Windows variants) onto a single source tree so coverage
reports reconcile correctly across runners.

The `[run]` section turns on branch coverage and the parallel
writer (combine-after-run model). covdefaults loads via plugins.
`source_pkgs` restricts measurement to the `tox_plugins` namespace.

🧪 Force `ctrace` core in coveragepy

This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Signed-off-by: Sviatoslav Sydorenko <[email protected]>
webknjaz added a commit to webknjaz/tox-dev--tox-sphinx that referenced this pull request Nov 14, 2026
Coverage runs under the covdefaults plugin (sensible exclusion
defaults for branch coverage, ignored boilerplate, common
optional-imports patterns).

Two additional `exclude_also` entries beyond covdefaults: the
`@pytest.mark.xfail` decorator pattern, and the project-local
`if _t.TYPE_CHECKING:` form. The header comment references
coverage's and covdefaults' canonical exclusion lists so the
deltas are easy to audit later (the comment shape comes from
jazzband/pip-tools).

The `[paths]` section maps multi-layout site-packages locations
(`src/` next to `*/src` for tox envs, posix `lib/python*` next to
pypy and Windows variants) onto a single source tree so coverage
reports reconcile correctly across runners.

The `[run]` section turns on branch coverage and the parallel
writer (combine-after-run model). covdefaults loads via plugins.
`source_pkgs` restricts measurement to the `tox_plugins` namespace.

🧪 Force `ctrace` core in coveragepy

This will allow correct coverage collection with dynamic coverage
enabled and will avoid warnings that coveragepy v7.15.3 started emitting
and our configuration is turning into hard errors.

* aio-libs/multidict#1393
* pytest-dev/pytest-cov#755
* https://coverage.rtfd.io/en/latest/changes.html#version-7-15-3-2026-08-02
* coveragepy/coveragepy#2200
* coveragepy/coveragepy#2234

Signed-off-by: Sviatoslav Sydorenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysmon core silently drops contexts set via switch_context() (no warning, no fallback)

3 participants