Skip to content

Commit 1b94260

Browse files
committed
Fix errors in the test suite due to pytest warning changes
This is causing CI failures for some builds. This is really a pytest bug (pytest-dev/pytest#2430), but working around this on our end is easy enough (and cleans things up a little).
1 parent ab4ffee commit 1b94260

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

xarray/tests/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import division
33
from __future__ import print_function
4-
import warnings
54
from contextlib import contextmanager
65
from distutils.version import LooseVersion
76

@@ -119,11 +118,10 @@ def assertItemsEqual(self, first, second, msg=None):
119118

120119
@contextmanager
121120
def assertWarns(self, message):
122-
with warnings.catch_warnings(record=True) as w:
123-
warnings.filterwarnings('always', message)
121+
with pytest.warns(Warning) as w:
124122
yield
125-
assert len(w) > 0
126-
assert any(message in str(wi.message) for wi in w)
123+
assert len(w) > 0
124+
assert any(message in str(wi.message) for wi in w)
127125

128126
def assertVariableEqual(self, v1, v2):
129127
assert_equal(v1, v2)

xarray/tests/test_dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ def test_to_dataset_whole(self):
23212321
self.assertDatasetIdentical(expected, actual)
23222322

23232323
expected = Dataset({'bar': ('x', [1, 2])})
2324-
with self.assertWarns('order of the arguments'):
2324+
with pytest.deprecated_call():
23252325
actual = named.to_dataset('bar')
23262326
self.assertDatasetIdentical(expected, actual)
23272327

xarray/tests/test_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Arbitrary(object):
274274
self.assertDatasetIdentical(expected, actual)
275275

276276
def test_constructor_deprecated(self):
277-
with self.assertWarns('deprecated'):
277+
with pytest.deprecated_call():
278278
DataArray([1, 2, 3], coords={'x': [0, 1, 2]})
279279

280280
def test_constructor_auto_align(self):

0 commit comments

Comments
 (0)