diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 82c11468e..e2cca7560 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -999,6 +999,7 @@ TEST_SUBMODULE(pytypes, m) { m.attr("defined_PYBIND11_TEST_PYTYPES_HAS_RANGES") = false; #endif +#if defined(PYBIND11_CPP17) m.attr_with_type>("list_int") = py::list(); m.attr_with_type>("set_str") = py::set(); @@ -1014,4 +1015,8 @@ TEST_SUBMODULE(pytypes, m) { point.attr_with_type>("dict_str_int") = py::dict(); m.attr_with_type>("CONST_INT") = 3; + m.attr("defined_PYBIND11_CPP17") = true; +#else + m.attr("defined_PYBIND11_CPP17") = false; +#endif } diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 44f161a14..9ae2f4ff9 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -1105,19 +1105,24 @@ def test_dict_ranges(tested_dict, expected): # https://docs.python.org/3/howto/annotations.html#accessing-the-annotations-dict-of-an-object-in-python-3-9-and-older def get_annotations_helper(o): - print(dir(o)) if isinstance(o, type): return o.__dict__.get("__annotations__", {}) return getattr(o, "__annotations__", {}) - +@pytest.mark.skipif( + not m.defined_PYBIND11_CPP17, + reason="C++17 Position Independent Code not available", +) def test_module_attribute_types() -> None: module_annotations = get_annotations_helper(m) assert module_annotations["list_int"] == "list[int]" assert module_annotations["set_str"] == "set[str]" - +@pytest.mark.skipif( + not m.defined_PYBIND11_CPP17, + reason="C++17 Position Independent Code not available", +) def test_class_attribute_types() -> None: empty_annotations = get_annotations_helper(m.EmptyAnnotationClass) annotations = get_annotations_helper(m.Point) @@ -1126,7 +1131,10 @@ def test_class_attribute_types() -> None: assert annotations["x"] == "float" assert annotations["dict_str_int"] == "dict[str, int]" - +@pytest.mark.skipif( + not m.defined_PYBIND11_CPP17, + reason="C++17 Position Independent Code not available", +) def test_final_annotation() -> None: module_annotations = get_annotations_helper(m) assert module_annotations["CONST_INT"] == "Final[int]"