-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Pytest 3.8.0 broke some NumPy tests. #3945
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
Comments
Hi @charris, Here's what's happening: The class class TestNewScalarIndexing(object):
a = matrix([[1, 2], [3, 4]]) (from here). This construct emits the warning you posted, which was being ignored in previous pytest versions because we did not capture warnings during collection (#3251). Now in 3.8 this issue has been fixed, so pytest is capturing the warning during collection and it is raising an exception according to your configuration. The In summary things are working as they should, it is just that fixing #3251 now makes it clear that a warning was being raised during collection where it was being ignored in previous pytest versions. I see two easy ways to fix this:
|
Moving into |
Hmm it should work with Changing the code as suggested in 2) is not an option? I was about to open a PR moving the configuration to |
Note that I had to adjust the stacklevel for the option approach to work for 3.7.4, but it does not work in 3.8. Could the option order make a difference? |
It shouldn't, I will look into that. I've applied option 2) locally and it passes, here's the diff: diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index 272cd8d52..dcadbfa7b 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -342,7 +342,10 @@ class TestIndexing(object):
class TestNewScalarIndexing(object):
- a = matrix([[1, 2], [3, 4]])
+
+ @property
+ def a(self):
+ return matrix([[1, 2], [3, 4]])
def test_dimesions(self):
a = self.a
@@ -421,8 +424,13 @@ class TestPower(object):
class TestShape(object):
- a = np.array([[1], [2]])
- m = matrix([[1], [2]])
+ @property
+ def a(self):
+ return np.array([[1], [2]])
+
+ @property
+ def m(self):
+ return matrix([[1], [2]])
def test_shape(self):
assert_equal(self.a.shape, (2, 1))
@@ -460,12 +468,14 @@ class TestShape(object):
assert_equal(x.T.ravel(order='A'), [[1, 2, 3, 4, 5, 6]])
def test_array_memory_sharing(self):
- assert_(np.may_share_memory(self.a, self.a.ravel()))
- assert_(not np.may_share_memory(self.a, self.a.flatten()))
+ a = self.a
+ assert_(np.may_share_memory(a, a.ravel()))
+ assert_(not np.may_share_memory(a, a.flatten()))
def test_matrix_memory_sharing(self):
- assert_(np.may_share_memory(self.m, self.m.ravel()))
- assert_(not np.may_share_memory(self.m, self.m.flatten()))
+ m = self.m
+ assert_(np.may_share_memory(m, m.ravel()))
+ assert_(not np.may_share_memory(m, m.flatten()))
def test_expand_dims_matrix(self):
# matrices are always 2d - so expand_dims only makes sense when the If that sounds reasonable to you, I can open a PR with this fix. |
Well, we could revisit that. But there are some warnings we want to error for development testing but not in releases, so for development we set the default warning behavior to |
Oh but option 2) doesn't require changing any of that, we just change the code slightly so the warning is not triggered during collection. |
There are more tests :) That fix does not make me happy, it is a bit obscure, but it looks like the approach is lazy generation of the test matrices. We could go that way, setup/teardown would have the same effect I suppose, but if you plan to fix pytest so that the option approach works, I'll just pin pytest to an earlier version. |
Oh definitely. Pinning the version to |
I investigated the reason why But IIUC, for your use case where the |
Let me check... Yes, the command line options work when pytest.ini is not present. |
The order of precedence almost seems backward, but that is probably one of those things that could be argued at length. |
Great, so I think you can go with that route now then. 👍 I opened #3946 to change the precedence order, but I believe this kind of change will have to wait for 3.9 because there might be users which rely on the current precedence of the options. |
Thanks for all the help. |
I'll close this for now. |
Sure, glad to help. Thanks. |
Pytest < 3.8 ignored warnings issued during test collection, but that changed in pytest 3.8 and the method NumPy used to suppress the PendingDeprecationWarning for matrices no longer worked, or rather, was exposed as not working. The fix here is to suppress the warning in pytest.ini and pytesttester.py , which should work as long as the tests are the only places left where NumPy uses matrices. An alternate fix is to delay the construction of matrices in the tests until they are actually run, which has the virtue of test localization but is a bit more complicated. See pytest-dev/pytest#3945 for discussion.
Pytest < 3.8 ignored warnings issued during test collection, but that changed in pytest 3.8 and the method NumPy used to suppress the PendingDeprecationWarning for matrices no longer worked, or rather, was exposed as not working. The fix here is to suppress the warning in pytest.ini and pytesttester.py , which should work as long as the tests are the only places left where NumPy uses matrices. An alternate fix is to delay the construction of matrices in the tests until they are actually run, which has the virtue of test localization but is a bit more complicated. See pytest-dev/pytest#3945 for discussion.
See numpy/numpy#11895 for comments and https://travis-ci.org/numpy/numpy/jobs/425358526 for failing tests. The tests pass with pytest 3.6.1, but fail with 3.8.0. The failing warning is disabled in the tests by
But this seems to no longer succeed for parametrized tests. The error message with latest NumPy master is
Thanks for submitting an issue!
Here's a quick checklist in what to include:
pip list
of the virtual environment you are usingThe text was updated successfully, but these errors were encountered: