From b2de38fe5cecf778cdccfd93b29eb3783d2b2a64 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 31 Jan 2021 21:51:30 +0100 Subject: [PATCH 1/4] Make sure all warnings in pytest get turned into errors --- tests/pytest.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pytest.ini b/tests/pytest.ini index c47cbe9c1e..a3871d6c3a 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -7,11 +7,11 @@ addopts = -rs # capture only Python print and C++ py::print, but not C output (low-level Python errors) --capture=sys - # enable all warnings - -Wa filterwarnings = # make warnings into errors but ignore certain third-party extension issues error + # somehow, some DeprecationWarnings do not get turned into errors + always::DeprecationWarning # importing scipy submodules on some version of Python ignore::ImportWarning # bogus numpy ABI warning (see numpy/#432) From a5a58468ec8bc0c466039d5f011177e7ed232360 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 31 Jan 2021 22:02:37 +0100 Subject: [PATCH 2/4] Suppress DeprecationWarnings in test_int_convert and test_numpy_int_convert --- tests/test_builtin_casters.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py index cb37dbcb3e..860f34e24a 100644 --- a/tests/test_builtin_casters.py +++ b/tests/test_builtin_casters.py @@ -299,7 +299,9 @@ def cant_convert(v): assert convert(7) == 7 assert noconvert(7) == 7 cant_convert(3.14159) - assert convert(Int()) == 42 + # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) + with pytest.deprecated_call(): + assert convert(Int()) == 42 requires_conversion(Int()) cant_convert(NotInt()) cant_convert(Float()) @@ -329,7 +331,9 @@ def require_implicit(v): assert noconvert(np.intc(42)) == 42 # The implicit conversion from np.float32 is undesirable but currently accepted. - assert convert(np.float32(3.14159)) == 3 + # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) + with pytest.deprecated_call(): + assert convert(np.float32(3.14159)) == 3 require_implicit(np.float32(3.14159)) From f001e413280d4875d23da793effa9665fa52bc1e Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 31 Jan 2021 22:27:13 +0100 Subject: [PATCH 3/4] PyLong_AsLong only shouts "Deprecated!" on Python>=3.8 --- tests/test_builtin_casters.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py index 860f34e24a..45963f6353 100644 --- a/tests/test_builtin_casters.py +++ b/tests/test_builtin_casters.py @@ -300,7 +300,10 @@ def cant_convert(v): assert noconvert(7) == 7 cant_convert(3.14159) # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) - with pytest.deprecated_call(): + if env.PY >= (3, 8): + with pytest.deprecated_call(): + assert convert(Int()) == 42 + else: assert convert(Int()) == 42 requires_conversion(Int()) cant_convert(NotInt()) @@ -332,7 +335,10 @@ def require_implicit(v): # The implicit conversion from np.float32 is undesirable but currently accepted. # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) - with pytest.deprecated_call(): + if env.PY >= (3, 8): + with pytest.deprecated_call(): + assert convert(np.float32(3.14159)) == 3 + else: assert convert(np.float32(3.14159)) == 3 require_implicit(np.float32(3.14159)) From c68411bcc127b0e22281886289ded95c7043a5e4 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 31 Jan 2021 23:28:16 +0100 Subject: [PATCH 4/4] Fix remaining warnings on PyPy and CPython 3.10-dev --- tests/test_builtin_casters.py | 4 ++-- tests/test_class.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py index 45963f6353..fda0384333 100644 --- a/tests/test_builtin_casters.py +++ b/tests/test_builtin_casters.py @@ -300,7 +300,7 @@ def cant_convert(v): assert noconvert(7) == 7 cant_convert(3.14159) # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) - if env.PY >= (3, 8): + if (3, 8) <= env.PY < (3, 10): with pytest.deprecated_call(): assert convert(Int()) == 42 else: @@ -335,7 +335,7 @@ def require_implicit(v): # The implicit conversion from np.float32 is undesirable but currently accepted. # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) - if env.PY >= (3, 8): + if (3, 8) <= env.PY < (3, 10): with pytest.deprecated_call(): assert convert(np.float32(3.14159)) == 3 else: diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 6ce928ca95..bd545e8c68 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -434,8 +434,7 @@ TEST_SUBMODULE(class_, m) { struct SamePointer {}; static SamePointer samePointer; py::class_>(m, "SamePointer") - .def(py::init([]() { return &samePointer; })) - .def("__del__", [](SamePointer&) { py::print("__del__ called"); }); + .def(py::init([]() { return &samePointer; })); struct Empty {}; py::class_(m, "Empty")