@@ -103,38 +103,48 @@ def do_remove_extension(*args):
103
103
print (f"Couldn't remove { filename } : { exc } " )
104
104
105
105
106
- def label_for_tracer ( tracer ):
106
+ def label_for_core ( core ):
107
107
"""Get the label for these tests."""
108
- if tracer == "py" :
109
- label = "with Python tracer"
108
+ if core == "pytrace" :
109
+ return "with Python tracer"
110
+ elif core == "ctrace" :
111
+ return "with C tracer"
112
+ elif core == "sysmon" :
113
+ return "with sys.monitoring"
110
114
else :
111
- label = "with C tracer"
115
+ raise ValueError ( f"Bad core: { core !r } " )
112
116
113
- return label
114
117
118
+ def should_skip (core ):
119
+ """Is there a reason to skip these tests?
115
120
116
- def should_skip (tracer ):
117
- """Is there a reason to skip these tests?"""
121
+ Return empty string to run tests, or a message about why we are skipping
122
+ the tests.
123
+ """
118
124
skipper = ""
119
125
120
- # $set_env.py: COVERAGE_ONE_TRACER - Only run tests for one tracer.
121
- only_one = os .getenv ("COVERAGE_ONE_TRACER" )
122
- if only_one :
123
- if CPYTHON :
124
- if tracer == "py" :
125
- skipper = "Only one tracer: no Python tracer for CPython"
126
- else :
127
- if tracer == "c" :
128
- skipper = f"No C tracer for { platform .python_implementation ()} "
129
- elif tracer == "py" :
130
- # $set_env.py: COVERAGE_NO_PYTRACER - Don't run the tests under the Python tracer.
131
- skipper = os .getenv ("COVERAGE_NO_PYTRACER" )
126
+ # $set_env.py: COVERAGE_TEST_CORES - List of cores to run
127
+ test_cores = os .getenv ("COVERAGE_TEST_CORES" )
128
+ if test_cores :
129
+ if core not in test_cores :
130
+ skipper = f"core { core } not in COVERAGE_TEST_CORES={ test_cores } "
131
+
132
132
else :
133
- # $set_env.py: COVERAGE_NO_CTRACER - Don't run the tests under the C tracer.
134
- skipper = os .getenv ("COVERAGE_NO_CTRACER" )
133
+ # $set_env.py: COVERAGE_ONE_CORE - Only run tests for one core.
134
+ only_one = os .getenv ("COVERAGE_ONE_CORE" )
135
+ if only_one :
136
+ if CPYTHON :
137
+ if sys .version_info >= (3 , 12 ):
138
+ if core != "sysmon" :
139
+ skipper = f"Only one core: not running { core } "
140
+ elif core != "ctrace" :
141
+ skipper = f"Only one core: not running { core } "
142
+ else :
143
+ if core != "pytrace" :
144
+ skipper = f"No C core for { platform .python_implementation ()} "
135
145
136
146
if skipper :
137
- msg = "Skipping tests " + label_for_tracer ( tracer )
147
+ msg = "Skipping tests " + label_for_core ( core )
138
148
if len (skipper ) > 1 :
139
149
msg += ": " + skipper
140
150
else :
@@ -143,26 +153,26 @@ def should_skip(tracer):
143
153
return msg
144
154
145
155
146
- def make_env_id (tracer ):
156
+ def make_env_id (core ):
147
157
"""An environment id that will keep all the test runs distinct."""
148
158
impl = platform .python_implementation ().lower ()
149
159
version = "%s%s" % sys .version_info [:2 ]
150
160
if PYPY :
151
161
version += "_%s%s" % sys .pypy_version_info [:2 ]
152
- env_id = f"{ impl } { version } _{ tracer } "
162
+ env_id = f"{ impl } { version } _{ core } "
153
163
return env_id
154
164
155
165
156
- def run_tests (tracer , * runner_args ):
166
+ def run_tests (core , * runner_args ):
157
167
"""The actual running of tests."""
158
168
if "COVERAGE_TESTING" not in os .environ :
159
169
os .environ ["COVERAGE_TESTING" ] = "True"
160
- print_banner (label_for_tracer ( tracer ))
170
+ print_banner (label_for_core ( core ))
161
171
162
172
return pytest .main (list (runner_args ))
163
173
164
174
165
- def run_tests_with_coverage (tracer , * runner_args ):
175
+ def run_tests_with_coverage (core , * runner_args ):
166
176
"""Run tests, but with coverage."""
167
177
# Need to define this early enough that the first import of env.py sees it.
168
178
os .environ ["COVERAGE_TESTING" ] = "True"
@@ -172,7 +182,7 @@ def run_tests_with_coverage(tracer, *runner_args):
172
182
if context :
173
183
if context [0 ] == "$" :
174
184
context = os .environ [context [1 :]]
175
- os .environ ["COVERAGE_CONTEXT" ] = context + "." + tracer
185
+ os .environ ["COVERAGE_CONTEXT" ] = context + "." + core
176
186
177
187
# Create the .pth file that will let us measure coverage in sub-processes.
178
188
# The .pth file seems to have to be alphabetically after easy-install.pth
@@ -183,7 +193,7 @@ def run_tests_with_coverage(tracer, *runner_args):
183
193
with open (pth_path , "w" ) as pth_file :
184
194
pth_file .write ("import coverage; coverage.process_startup()\n " )
185
195
186
- suffix = f"{ make_env_id (tracer )} _{ platform .platform ()} "
196
+ suffix = f"{ make_env_id (core )} _{ platform .platform ()} "
187
197
os .environ ["COVERAGE_METAFILE" ] = os .path .abspath (".metacov." + suffix )
188
198
189
199
import coverage
@@ -211,7 +221,7 @@ def run_tests_with_coverage(tracer, *runner_args):
211
221
sys .modules .update (covmods )
212
222
213
223
# Run tests, with the arguments from our command line.
214
- status = run_tests (tracer , * runner_args )
224
+ status = run_tests (core , * runner_args )
215
225
216
226
finally :
217
227
cov .stop ()
@@ -240,19 +250,19 @@ def do_combine_html():
240
250
cov .html_report (show_contexts = show_contexts )
241
251
242
252
243
- def do_test_with_tracer ( tracer , * runner_args ):
244
- """Run tests with a particular tracer ."""
253
+ def do_test_with_core ( core , * runner_args ):
254
+ """Run tests with a particular core ."""
245
255
# If we should skip these tests, skip them.
246
- skip_msg = should_skip (tracer )
256
+ skip_msg = should_skip (core )
247
257
if skip_msg :
248
258
print (skip_msg )
249
259
return None
250
260
251
- os .environ ["COVERAGE_TEST_TRACER " ] = tracer
261
+ os .environ ["COVERAGE_CORE " ] = core
252
262
if os .getenv ("COVERAGE_COVERAGE" , "no" ) == "yes" :
253
- return run_tests_with_coverage (tracer , * runner_args )
263
+ return run_tests_with_coverage (core , * runner_args )
254
264
else :
255
- return run_tests (tracer , * runner_args )
265
+ return run_tests (core , * runner_args )
256
266
257
267
258
268
def do_zip_mods ():
0 commit comments