|
1 | 1 | from __future__ import print_function |
2 | 2 | import sys |
| 3 | +import sysconfig |
3 | 4 | import greenlet |
4 | 5 | import unittest |
5 | 6 |
|
6 | 7 | from . import TestCase |
7 | 8 | from . import PY312 |
8 | 9 |
|
9 | 10 | # https://discuss.python.org/t/cpython-3-12-greenlet-and-tracing-profiling-how-to-not-crash-and-get-correct-results/33144/2 |
10 | | -DEBUG_BUILD_PY312 = ( |
11 | | - PY312 and hasattr(sys, 'gettotalrefcount'), |
12 | | - "Broken on debug builds of Python 3.12" |
| 11 | +# When build variables are available, OPT is the best way of detecting |
| 12 | +# the build with assertions enabled. Otherwise, fallback to detecting PyDEBUG |
| 13 | +# build. |
| 14 | +ASSERTION_BUILD_PY312 = ( |
| 15 | + PY312 and ( |
| 16 | + "-DNDEBUG" not in sysconfig.get_config_var("OPT").split() |
| 17 | + if sysconfig.get_config_var("OPT") is not None |
| 18 | + else hasattr(sys, 'gettotalrefcount') |
| 19 | + ), |
| 20 | + "Broken on assertion-enabled builds of Python 3.12" |
13 | 21 | ) |
14 | 22 |
|
15 | 23 | class SomeError(Exception): |
@@ -198,7 +206,7 @@ def run(self): |
198 | 206 |
|
199 | 207 | self._check_trace_events_from_greenlet_sets_profiler(X(), tracer) |
200 | 208 |
|
201 | | - @unittest.skipIf(*DEBUG_BUILD_PY312) |
| 209 | + @unittest.skipIf(*ASSERTION_BUILD_PY312) |
202 | 210 | def test_trace_events_multiple_greenlets_switching(self): |
203 | 211 | tracer = PythonTracer() |
204 | 212 |
|
@@ -236,7 +244,7 @@ def g2_run(): |
236 | 244 | ('c_call', '__exit__'), |
237 | 245 | ]) |
238 | 246 |
|
239 | | - @unittest.skipIf(*DEBUG_BUILD_PY312) |
| 247 | + @unittest.skipIf(*ASSERTION_BUILD_PY312) |
240 | 248 | def test_trace_events_multiple_greenlets_switching_siblings(self): |
241 | 249 | # Like the first version, but get both greenlets running first |
242 | 250 | # as "siblings" and then establish the tracing. |
|
0 commit comments