Skip to content

Commit b288f43

Browse files
authored
Merge pull request #457 from mgorny/fix-assert-test-skips
Fix py312+ crash test skips to correctly check for assertions
2 parents b24e39c + 739cc55 commit b288f43

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/greenlet/tests/test_tracing.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
from __future__ import print_function
22
import sys
3+
import sysconfig
34
import greenlet
45
import unittest
56

67
from . import TestCase
78
from . import PY312
89

910
# 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"
1321
)
1422

1523
class SomeError(Exception):
@@ -198,7 +206,7 @@ def run(self):
198206

199207
self._check_trace_events_from_greenlet_sets_profiler(X(), tracer)
200208

201-
@unittest.skipIf(*DEBUG_BUILD_PY312)
209+
@unittest.skipIf(*ASSERTION_BUILD_PY312)
202210
def test_trace_events_multiple_greenlets_switching(self):
203211
tracer = PythonTracer()
204212

@@ -236,7 +244,7 @@ def g2_run():
236244
('c_call', '__exit__'),
237245
])
238246

239-
@unittest.skipIf(*DEBUG_BUILD_PY312)
247+
@unittest.skipIf(*ASSERTION_BUILD_PY312)
240248
def test_trace_events_multiple_greenlets_switching_siblings(self):
241249
# Like the first version, but get both greenlets running first
242250
# as "siblings" and then establish the tracing.

0 commit comments

Comments
 (0)