Skip to content

Commit 3f111a4

Browse files
committed
BUG: Fix matrix PendingDeprecationWarning suppression for pytest 3.8+.
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.
1 parent b8f3be9 commit 3f111a4

File tree

9 files changed

+30
-50
lines changed

9 files changed

+30
-50
lines changed

numpy/_pytesttester.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ def __call__(self, label='fast', verbose=1, extra_argv=None,
160160
"-W ignore::UserWarning:cpuinfo",
161161
]
162162

163+
# When testing matrices, ignore their PendingDeprecationWarnings
164+
pytest_args += [
165+
"-W ignore:the matrix subclass is not",
166+
]
167+
168+
# Ignore python2.7 -3 warnings
169+
pytest_args += [
170+
r"-W ignore:sys\.exc_clear\(\) not supported in 3\.x:DeprecationWarning",
171+
r"-W ignore:in 3\.x, __setslice__:DeprecationWarning",
172+
r"-W ignore:in 3\.x, __getslice__:DeprecationWarning",
173+
r"-W ignore:buffer\(\) not supported in 3\.x:DeprecationWarning",
174+
r"-W ignore:CObject type is not supported in 3\.x:DeprecationWarning",
175+
r"-W ignore:comparing unequal types not supported in 3\.x:DeprecationWarning",
176+
r"-W ignore:the commands module has been removed in Python 3\.0:DeprecationWarning",
177+
r"-W ignore:The 'new' module has been removed in Python 3\.0:DeprecationWarning",
178+
]
179+
180+
163181
if doctests:
164182
raise ValueError("Doctests not supported")
165183

numpy/matrixlib/tests/test_defmatrix.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import division, absolute_import, print_function
22

3-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4-
try:
5-
import pytest
6-
pytestmark = pytest.mark.filterwarnings(
7-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8-
except ImportError:
9-
pass
3+
import pytest
104

115
try:
126
# Accessing collections abstract classes from collections

numpy/matrixlib/tests/test_interaction.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
"""
55
from __future__ import division, absolute_import, print_function
66

7-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
8-
try:
9-
import pytest
10-
pytestmark = pytest.mark.filterwarnings(
11-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
12-
except ImportError:
13-
pass
7+
import pytest
148

159
import textwrap
1610
import warnings

numpy/matrixlib/tests/test_masked_matrix.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
from __future__ import division, absolute_import, print_function
22

3-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4-
try:
5-
import pytest
6-
pytestmark = pytest.mark.filterwarnings(
7-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8-
except ImportError:
9-
pass
10-
113
import pickle
4+
import pytest
125

136
import numpy as np
147
from numpy.ma.testutils import (assert_, assert_equal, assert_raises,

numpy/matrixlib/tests/test_matrix_linalg.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
""" Test functions for linalg module using the matrix class."""
22
from __future__ import division, absolute_import, print_function
33

4-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
5-
try:
6-
import pytest
7-
pytestmark = pytest.mark.filterwarnings(
8-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
9-
except ImportError:
10-
pass
4+
import pytest
115

126
import numpy as np
137

numpy/matrixlib/tests/test_multiarray.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import division, absolute_import, print_function
22

3-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4-
try:
5-
import pytest
6-
pytestmark = pytest.mark.filterwarnings(
7-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8-
except ImportError:
9-
pass
3+
import pytest
104

115
import numpy as np
126
from numpy.testing import assert_, assert_equal, assert_array_equal

numpy/matrixlib/tests/test_numeric.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import division, absolute_import, print_function
22

3-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4-
try:
5-
import pytest
6-
pytestmark = pytest.mark.filterwarnings(
7-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8-
except ImportError:
9-
pass
3+
import pytest
104

115
import numpy as np
126
from numpy.testing import assert_equal

numpy/matrixlib/tests/test_regression.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import division, absolute_import, print_function
22

3-
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4-
try:
5-
import pytest
6-
pytestmark = pytest.mark.filterwarnings(
7-
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8-
except ImportError:
9-
pass
3+
import pytest
104

115
import numpy as np
126
from numpy.testing import assert_, assert_equal, assert_raises

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ filterwarnings =
99
ignore:Not importing directory
1010
ignore:numpy.dtype size changed
1111
ignore:numpy.ufunc size changed
12+
ignore::UserWarning:cpuinfo,
13+
# Matrix PendingDeprecationWarning.
14+
ignore:the matrix subclass is not
1215
# Ignore python2.7 -3 warnings
1316
ignore:sys\.exc_clear\(\) not supported in 3\.x:DeprecationWarning
1417
ignore:in 3\.x, __setslice__:DeprecationWarning
@@ -17,5 +20,7 @@ filterwarnings =
1720
ignore:CObject type is not supported in 3\.x:DeprecationWarning
1821
ignore:comparing unequal types not supported in 3\.x:DeprecationWarning
1922
ignore:the commands module has been removed in Python 3\.0:DeprecationWarning
23+
ignore:The 'new' module has been removed in Python 3\.0:DeprecationWarning
24+
2025
env =
2126
PYTHONHASHSEED=0

0 commit comments

Comments
 (0)