Skip to content

Commit 91e323f

Browse files
committed
Tests log the Python version
1 parent 59b1b84 commit 91e323f

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

tests/test_pythoncapi_compat.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,22 @@ def run_tests(module_name, lang):
143143
print()
144144
return
145145

146-
if VERBOSE and hasattr(testmod, "__cplusplus"):
147-
print("__cplusplus: %s" % testmod.__cplusplus)
146+
if VERBOSE:
147+
empty_line = False
148+
for attr in ('__cplusplus', 'PY_VERSION', 'PY_VERSION_HEX',
149+
'PYPY_VERSION', 'PYPY_VERSION_NUM'):
150+
try:
151+
value = getattr(testmod, attr)
152+
except AttributeError:
153+
pass
154+
else:
155+
if attr in ("PY_VERSION_HEX", "PYPY_VERSION_NUM"):
156+
value = "0x%x" % value
157+
print("%s: %s" % (attr, value))
158+
empty_line = True
159+
160+
if empty_line:
161+
print()
148162

149163
check_refleak = hasattr(sys, 'gettotalrefcount')
150164

tests/test_pythoncapi_compat_cext.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -1222,22 +1222,32 @@ static struct PyMethodDef methods[] = {
12221222
};
12231223

12241224

1225-
#ifdef __cplusplus
12261225
static int
12271226
module_exec(PyObject *module)
12281227
{
1228+
#ifdef __cplusplus
12291229
if (PyModule_AddIntMacro(module, __cplusplus)) {
12301230
return -1;
12311231
}
1232+
#endif
1233+
if (PyModule_AddStringMacro(module, PY_VERSION)) {
1234+
return -1;
1235+
}
1236+
if (PyModule_AddIntMacro(module, PY_VERSION_HEX)) {
1237+
return -1;
1238+
}
1239+
#ifdef PYPY_VERSION
1240+
if (PyModule_AddStringMacro(module, PYPY_VERSION)) {
1241+
return -1;
1242+
}
1243+
#endif
1244+
#ifdef PYPY_VERSION_NUM
1245+
if (PyModule_AddIntMacro(module, PYPY_VERSION_NUM)) {
1246+
return -1;
1247+
}
1248+
#endif
12321249
return 0;
12331250
}
1234-
#else
1235-
static int
1236-
module_exec(PyObject *Py_UNUSED(module))
1237-
{
1238-
return 0;
1239-
}
1240-
#endif
12411251

12421252

12431253
#if PY_VERSION_HEX >= 0x03050000

0 commit comments

Comments
 (0)