Skip to content

Commit fe84587

Browse files
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
1 parent 721834b commit fe84587

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

tests/pytest.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ addopts =
77
-rs
88
# capture only Python print and C++ py::print, but not C output (low-level Python errors)
99
--capture=sys
10-
# enable all warnings
11-
-Wa
1210
filterwarnings =
1311
# make warnings into errors but ignore certain third-party extension issues
1412
error
13+
# somehow, some DeprecationWarnings do not get turned into errors
14+
always::DeprecationWarning
1515
# importing scipy submodules on some version of Python
1616
ignore::ImportWarning
1717
# bogus numpy ABI warning (see numpy/#432)

tests/test_builtin_casters.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,12 @@ def cant_convert(v):
299299
assert convert(7) == 7
300300
assert noconvert(7) == 7
301301
cant_convert(3.14159)
302-
assert convert(Int()) == 42
302+
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
303+
if (3, 8) <= env.PY < (3, 10):
304+
with pytest.deprecated_call():
305+
assert convert(Int()) == 42
306+
else:
307+
assert convert(Int()) == 42
303308
requires_conversion(Int())
304309
cant_convert(NotInt())
305310
cant_convert(Float())
@@ -329,7 +334,12 @@ def require_implicit(v):
329334
assert noconvert(np.intc(42)) == 42
330335

331336
# The implicit conversion from np.float32 is undesirable but currently accepted.
332-
assert convert(np.float32(3.14159)) == 3
337+
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
338+
if (3, 8) <= env.PY < (3, 10):
339+
with pytest.deprecated_call():
340+
assert convert(np.float32(3.14159)) == 3
341+
else:
342+
assert convert(np.float32(3.14159)) == 3
333343
require_implicit(np.float32(3.14159))
334344

335345

tests/test_class.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ TEST_SUBMODULE(class_, m) {
434434
struct SamePointer {};
435435
static SamePointer samePointer;
436436
py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
437-
.def(py::init([]() { return &samePointer; }))
438-
.def("__del__", [](SamePointer&) { py::print("__del__ called"); });
437+
.def(py::init([]() { return &samePointer; }));
439438

440439
struct Empty {};
441440
py::class_<Empty>(m, "Empty")

0 commit comments

Comments
 (0)