Skip to content

Commit 287afa6

Browse files
committed
wip: better core choices and warnings
1 parent 3328fad commit 287afa6

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

coverage/control.py

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ def _init_for_start(self) -> None:
549549
self._core = Core(
550550
warn=self._warn,
551551
config=self.config,
552+
dynamic_contexts=(should_start_context is not None),
552553
metacov=self._metacov,
553554
)
554555
self._collector = Collector(

coverage/core.py

+31-27
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from coverage.sysmon import SysMonitor
1919
from coverage.types import (
2020
TFileDisposition,
21-
Tracer,
2221
TWarnFn,
22+
Tracer,
2323
)
2424

2525

@@ -53,36 +53,40 @@ class Core:
5353
packed_arcs: bool
5454
systrace: bool
5555

56-
def __init__(self, warn: TWarnFn, config: CoverageConfig, metacov: bool) -> None:
57-
core_name: str | None
56+
def __init__(
57+
self,
58+
warn: TWarnFn,
59+
config: CoverageConfig,
60+
dynamic_contexts: bool,
61+
metacov: bool,
62+
) -> None:
63+
# Check the conditions that preclude us from using sys.monitoring.
64+
reason_no_sysmon = ""
65+
if not env.PYBEHAVIOR.pep669:
66+
reason_no_sysmon = "isn't available in this version"
67+
elif config.branch and not env.PYBEHAVIOR.branch_right_left:
68+
reason_no_sysmon = "can't measure branches in this version"
69+
elif dynamic_contexts:
70+
reason_no_sysmon = "doesn't yet support dynamic contexts"
71+
72+
core_name: str | None = None
5873
if config.timid:
5974
core_name = "pytrace"
60-
else:
75+
76+
if core_name is None:
6177
core_name = os.getenv("COVERAGE_CORE")
6278

63-
if core_name == "sysmon":
64-
if not env.PYBEHAVIOR.pep669:
65-
warn(
66-
"sys.monitoring isn't available in this version, using default core",
67-
slug="no-sysmon",
68-
)
69-
core_name = None
70-
71-
if config.branch and not env.PYBEHAVIOR.branch_right_left:
72-
warn(
73-
"sys.monitoring can't measure branches in this vesion, using default core",
74-
slug="no-sysmon",
75-
)
76-
core_name = None
77-
78-
if not core_name:
79-
# Once we're comfortable with sysmon as a default:
80-
# if env.PYBEHAVIOR.pep669 and self.should_start_context is None:
81-
# core_name = "sysmon"
82-
if HAS_CTRACER:
83-
core_name = "ctrace"
84-
else:
85-
core_name = "pytrace"
79+
if core_name == "sysmon" and reason_no_sysmon:
80+
warn(f"sys.monitoring {reason_no_sysmon}, using default core", slug="no-sysmon")
81+
core_name = None
82+
83+
if core_name is None:
84+
if not reason_no_sysmon:
85+
core_name = "sysmon"
86+
elif HAS_CTRACER:
87+
core_name = "ctrace"
88+
else:
89+
core_name = "pytrace"
8690

8791
self.tracer_kwargs = {}
8892

0 commit comments

Comments
 (0)