Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why, oh why, does python try so hard to hide deprecation warnings?!

Copy link
Collaborator Author

@YannickJadoul YannickJadoul Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have absolutely no clue. It gets funnier, btw: I added warnings.warn("abc", DeprecationWarning) in a test and that did get turned into an error!

But I didn't feel like wasting even more time, and digging further than https://github.com/python/cpython/blob/3c8d6934436e20163be802f5239c5b4e4925eeec/Objects/longobject.c#L226

Copy link
Collaborator

@henryiii henryiii Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, FutureWarning is (as clarified by PEP 565) the "user facing" deprecation warning.

# importing scipy submodules on some version of Python
ignore::ImportWarning
# bogus numpy ABI warning (see numpy/#432)
Expand Down
14 changes: 12 additions & 2 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ 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)
if (3, 8) <= env.PY < (3, 10):
with pytest.deprecated_call():
assert convert(Int()) == 42
else:
assert convert(Int()) == 42
requires_conversion(Int())
cant_convert(NotInt())
cant_convert(Float())
Expand Down Expand Up @@ -329,7 +334,12 @@ 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)
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))


Expand Down
3 changes: 1 addition & 2 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ TEST_SUBMODULE(class_, m) {
struct SamePointer {};
static SamePointer samePointer;
py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
.def(py::init([]() { return &samePointer; }))
.def("__del__", [](SamePointer&) { py::print("__del__ called"); });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this looks like a "sweep it under the carpet" kind of thing, you wouldn't be wrong. But we were never really using the fact that __del__ prints something anyway (possibly because it already didn't work on PyPy?).

.def(py::init([]() { return &samePointer; }));

struct Empty {};
py::class_<Empty>(m, "Empty")
Expand Down