Skip to content

Commit f6f964c

Browse files
committed
tests: update for GRAALPY 24.2 and better printout
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 8e22fbf commit f6f964c

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

tests/conftest.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import contextlib
1010
import difflib
1111
import gc
12+
import importlib.metadata
1213
import multiprocessing
1314
import re
1415
import sys
16+
import sysconfig
1517
import textwrap
1618
import traceback
1719

@@ -210,16 +212,32 @@ def pytest_configure():
210212
pytest.gc_collect = gc_collect
211213

212214

213-
def pytest_report_header(config):
214-
del config # Unused.
215+
def pytest_report_header():
215216
assert pybind11_tests.compiler_info is not None, (
216217
"Please update pybind11_tests.cpp if this assert fails."
217218
)
218-
return (
219-
"C++ Info:"
220-
f" {pybind11_tests.compiler_info}"
221-
f" {pybind11_tests.cpp_std}"
222-
f" {pybind11_tests.PYBIND11_INTERNALS_ID}"
223-
f" PYBIND11_SIMPLE_GIL_MANAGEMENT={pybind11_tests.PYBIND11_SIMPLE_GIL_MANAGEMENT}"
224-
f" PYBIND11_NUMPY_1_ONLY={pybind11_tests.PYBIND11_NUMPY_1_ONLY}"
225-
)
219+
interesting_packages = ("pybind11", "numpy", "scipy", "build")
220+
valid = []
221+
for package in sorted(interesting_packages):
222+
with contextlib.suppress(ModuleNotFoundError):
223+
valid.append(f"{package}=={importlib.metadata.version(package)}")
224+
reqs = " ".join(valid)
225+
226+
cpp_info = [
227+
"C++ Info:",
228+
f"{pybind11_tests.compiler_info}",
229+
f"{pybind11_tests.cpp_std}",
230+
f"{pybind11_tests.PYBIND11_INTERNALS_ID}",
231+
f"PYBIND11_SIMPLE_GIL_MANAGEMENT={pybind11_tests.PYBIND11_SIMPLE_GIL_MANAGEMENT}",
232+
f"PYBIND11_NUMPY_1_ONLY={pybind11_tests.PYBIND11_NUMPY_1_ONLY}",
233+
]
234+
if hasattr(pybind11_tests, "GRAALPY_VERSION_NUM"):
235+
cpp_info.append(f"GRAALPY_VERSION_NUM=0x{pybind11_tests.GRAALPY_VERSION_NUM:x}")
236+
lines = [
237+
f"installed packages of interest: {reqs}",
238+
" ".join(cpp_info),
239+
]
240+
if sysconfig.get_config_var("Py_GIL_DISABLED"):
241+
lines.append("free-threaded Python build")
242+
243+
return lines

tests/pybind11_tests.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ PYBIND11_MODULE(pybind11_tests, m, py::mod_gil_not_used()) {
104104
false;
105105
#endif
106106

107+
// Note that this is missing before GraalPy 24.2
108+
#if defined(GRAALPY_VERSION_NUM)
109+
m.attr("GRAALPY_VERSION_NUM") = GRAALPY_VERSION_NUM;
110+
#endif
111+
107112
bind_ConstructorStats(m);
108113

109114
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)

tests/test_enum.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66
import pytest
77

8-
import env # noqa: F401
8+
import env
9+
import pybind11_tests
910
from pybind11_tests import enums as m
1011

12+
GRAALPY_24_2 = env.GRAALPY and getattr(pybind11_tests, "GRAALPY_VERSION_NUM", 0) >= 0x180200
1113

12-
@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
14+
15+
@pytest.mark.xfail(env.GRAALPY and not GRAALPY_24_2, reason="Fixed in GraalPy 24.2")
1316
def test_unscoped_enum():
1417
assert str(m.UnscopedEnum.EOne) == "UnscopedEnum.EOne"
1518
assert str(m.UnscopedEnum.ETwo) == "UnscopedEnum.ETwo"
@@ -197,7 +200,7 @@ def test_implicit_conversion():
197200
assert repr(x) == "{<EMode.EFirstMode: 1>: 3, <EMode.ESecondMode: 2>: 4}"
198201

199202

200-
@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
203+
@pytest.mark.xfail(env.GRAALPY and not GRAALPY_24_2, reason="Fixed in GraalPy 24.2")
201204
def test_binary_operators():
202205
assert int(m.Flags.Read) == 4
203206
assert int(m.Flags.Write) == 2

tests/test_operator_overloading.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import pytest
44

55
import env
6+
import pybind11_tests
67
from pybind11_tests import ConstructorStats
78
from pybind11_tests import operators as m
89

10+
GRAALPY_24_2 = env.GRAALPY and getattr(pybind11_tests, "GRAALPY_VERSION_NUM", 0) >= 0x180200
11+
912

1013
@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
1114
def test_operator_overloading():
@@ -88,7 +91,7 @@ def test_operator_overloading():
8891
assert cstats.move_assignments == 0
8992

9093

91-
@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
94+
@pytest.mark.xfail(env.GRAALPY and not GRAALPY_24_2, reason="Fixed in GraalPy 24.2")
9295
def test_operators_notimplemented():
9396
"""#393: need to return NotSupported to ensure correct arithmetic operator behavior"""
9497

0 commit comments

Comments
 (0)