diff --git a/tests/test_embed/test_interpreter.cpp b/tests/test_embed/test_interpreter.cpp index 6299293b9..85e11ba62 100644 --- a/tests/test_embed/test_interpreter.cpp +++ b/tests/test_embed/test_interpreter.cpp @@ -169,8 +169,15 @@ TEST_CASE("There can be only one interpreter") { } bool has_pybind11_internals_builtin() { - auto builtins = py::handle(PyEval_GetBuiltins()); - return builtins.contains(PYBIND11_INTERNALS_ID); + py::dict state_dict; +#if PY_VERSION_HEX < 0x03080000 + state_dict = py::reinterpret_borrow(PyEval_GetBuiltins()); +#elif PY_VERSION_HEX < 0x03090000 + state_dict = py::reinterpret_borrow(PyInterpreterState_GetDict(_PyInterpreterState_Get())); +#else + state_dict = py::reinterpret_borrow(PyInterpreterState_GetDict(PyInterpreterState_Get())); +#endif + return state_dict.contains(PYBIND11_INTERNALS_ID); }; bool has_pybind11_internals_static() {