1616from coverage .misc import isolate_module
1717from coverage .pytracer import PyTracer
1818from coverage .sysmon import SysMonitor
19- from coverage .types import TFileDisposition , Tracer , TWarnFn
19+ from coverage .types import TDebugCtl , TFileDisposition , Tracer , TWarnFn
2020
2121os = isolate_module (os )
2222
@@ -56,11 +56,19 @@ class Core:
5656
5757 def __init__ (
5858 self ,
59+ * ,
5960 warn : TWarnFn ,
61+ debug : TDebugCtl | None ,
6062 config : CoverageConfig ,
6163 dynamic_contexts : bool ,
6264 metacov : bool ,
6365 ) -> None :
66+ def _debug (msg : str ) -> None :
67+ if debug :
68+ debug .write (msg )
69+
70+ _debug ("in core.py" )
71+
6472 # Check the conditions that preclude us from using sys.monitoring.
6573 reason_no_sysmon = ""
6674 if not env .PYBEHAVIOR .pep669 :
@@ -75,26 +83,34 @@ def __init__(
7583 core_name : str | None = None
7684 if config .timid :
7785 core_name = "pytrace"
86+ _debug ("core.py: Using pytrace because timid=True" )
7887 elif core_name is None :
7988 # This could still leave core_name as None.
8089 core_name = config .core
90+ _debug (f"core.py: core from config is { core_name !r} " )
8191
8292 if core_name == "sysmon" and reason_no_sysmon :
93+ _debug (f"core.py: raising ConfigError because sysmon not usable: { reason_no_sysmon } " )
8394 raise ConfigError (
8495 f"Can't use core=sysmon: sys.monitoring { reason_no_sysmon } " , skip_tests = True
8596 )
8697
8798 if core_name is None :
8899 if env .SYSMON_DEFAULT and not reason_no_sysmon :
89100 core_name = "sysmon"
101+ _debug ("core.py: Using sysmon because SYSMON_DEFAULT is set" )
90102 else :
91103 core_name = "ctrace"
104+ _debug ("core.py: Defaulting to ctrace core" )
92105
93106 if core_name == "ctrace" :
94107 if not CTRACER_FILE :
95108 if IMPORT_ERROR and env .SHIPPING_WHEELS :
96109 warn (f"Couldn't import C tracer: { IMPORT_ERROR } " , slug = "no-ctracer" , once = True )
97110 core_name = "pytrace"
111+ _debug ("core.py: Falling back to pytrace because C tracer not available" )
112+
113+ _debug (f"core.py: Using core={ core_name } " )
98114
99115 self .tracer_kwargs = {}
100116
0 commit comments