Commit fe845878 by Yannick Jadoul Committed by GitHub

Make sure all warnings in pytest get turned into errors (#2838)

* Make sure all warnings in pytest get turned into errors

* Suppress DeprecationWarnings in test_int_convert and test_numpy_int_convert

* PyLong_AsLong only shouts "Deprecated!" on Python>=3.8

* Fix remaining warnings on PyPy and CPython 3.10-dev
parent 721834b4
...@@ -7,11 +7,11 @@ addopts = ...@@ -7,11 +7,11 @@ addopts =
-rs -rs
# capture only Python print and C++ py::print, but not C output (low-level Python errors) # capture only Python print and C++ py::print, but not C output (low-level Python errors)
--capture=sys --capture=sys
# enable all warnings
-Wa
filterwarnings = filterwarnings =
# make warnings into errors but ignore certain third-party extension issues # make warnings into errors but ignore certain third-party extension issues
error error
# somehow, some DeprecationWarnings do not get turned into errors
always::DeprecationWarning
# importing scipy submodules on some version of Python # importing scipy submodules on some version of Python
ignore::ImportWarning ignore::ImportWarning
# bogus numpy ABI warning (see numpy/#432) # bogus numpy ABI warning (see numpy/#432)
......
...@@ -299,7 +299,12 @@ def test_int_convert(): ...@@ -299,7 +299,12 @@ def test_int_convert():
assert convert(7) == 7 assert convert(7) == 7
assert noconvert(7) == 7 assert noconvert(7) == 7
cant_convert(3.14159) cant_convert(3.14159)
assert convert(Int()) == 42 # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
if (3, 8) <= env.PY < (3, 10):
with pytest.deprecated_call():
assert convert(Int()) == 42
else:
assert convert(Int()) == 42
requires_conversion(Int()) requires_conversion(Int())
cant_convert(NotInt()) cant_convert(NotInt())
cant_convert(Float()) cant_convert(Float())
...@@ -329,7 +334,12 @@ def test_numpy_int_convert(): ...@@ -329,7 +334,12 @@ def test_numpy_int_convert():
assert noconvert(np.intc(42)) == 42 assert noconvert(np.intc(42)) == 42
# The implicit conversion from np.float32 is undesirable but currently accepted. # 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)
if (3, 8) <= env.PY < (3, 10):
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)) require_implicit(np.float32(3.14159))
......
...@@ -434,8 +434,7 @@ TEST_SUBMODULE(class_, m) { ...@@ -434,8 +434,7 @@ TEST_SUBMODULE(class_, m) {
struct SamePointer {}; struct SamePointer {};
static SamePointer samePointer; static SamePointer samePointer;
py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer") py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
.def(py::init([]() { return &samePointer; })) .def(py::init([]() { return &samePointer; }));
.def("__del__", [](SamePointer&) { py::print("__del__ called"); });
struct Empty {}; struct Empty {};
py::class_<Empty>(m, "Empty") py::class_<Empty>(m, "Empty")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment