Skip to content

Commit

Permalink
Tests log the Python version
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Aug 16, 2023
1 parent 59b1b84 commit 91e323f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
18 changes: 16 additions & 2 deletions tests/test_pythoncapi_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,22 @@ def run_tests(module_name, lang):
print()
return

if VERBOSE and hasattr(testmod, "__cplusplus"):
print("__cplusplus: %s" % testmod.__cplusplus)
if VERBOSE:
empty_line = False
for attr in ('__cplusplus', 'PY_VERSION', 'PY_VERSION_HEX',
'PYPY_VERSION', 'PYPY_VERSION_NUM'):
try:
value = getattr(testmod, attr)
except AttributeError:
pass
else:
if attr in ("PY_VERSION_HEX", "PYPY_VERSION_NUM"):
value = "0x%x" % value
print("%s: %s" % (attr, value))
empty_line = True

if empty_line:
print()

check_refleak = hasattr(sys, 'gettotalrefcount')

Expand Down
26 changes: 18 additions & 8 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,22 +1222,32 @@ static struct PyMethodDef methods[] = {
};


#ifdef __cplusplus
static int
module_exec(PyObject *module)
{
#ifdef __cplusplus
if (PyModule_AddIntMacro(module, __cplusplus)) {
return -1;
}
#endif
if (PyModule_AddStringMacro(module, PY_VERSION)) {
return -1;
}
if (PyModule_AddIntMacro(module, PY_VERSION_HEX)) {
return -1;
}
#ifdef PYPY_VERSION
if (PyModule_AddStringMacro(module, PYPY_VERSION)) {
return -1;
}
#endif
#ifdef PYPY_VERSION_NUM
if (PyModule_AddIntMacro(module, PYPY_VERSION_NUM)) {
return -1;
}
#endif
return 0;
}
#else
static int
module_exec(PyObject *Py_UNUSED(module))
{
return 0;
}
#endif


#if PY_VERSION_HEX >= 0x03050000
Expand Down

0 comments on commit 91e323f

Please sign in to comment.