From 1b942601b3bc39eac59f6626f4b112cb93686888 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Tue, 23 May 2017 23:51:19 -0700 Subject: [PATCH 1/3] 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 (https://github.com/pytest-dev/pytest/issues/2430), but working around this on our end is easy enough (and cleans things up a little). --- xarray/tests/__init__.py | 8 +++----- xarray/tests/test_dataarray.py | 2 +- xarray/tests/test_dataset.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index 95af04b9e40..be8a4277033 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -1,7 +1,6 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import warnings from contextlib import contextmanager from distutils.version import LooseVersion @@ -119,11 +118,10 @@ def assertItemsEqual(self, first, second, msg=None): @contextmanager def assertWarns(self, message): - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings('always', message) + with pytest.warns(Warning) as w: yield - assert len(w) > 0 - assert any(message in str(wi.message) for wi in w) + assert len(w) > 0 + assert any(message in str(wi.message) for wi in w) def assertVariableEqual(self, v1, v2): assert_equal(v1, v2) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 1396f73ce76..efcd58cb09d 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2321,7 +2321,7 @@ def test_to_dataset_whole(self): self.assertDatasetIdentical(expected, actual) expected = Dataset({'bar': ('x', [1, 2])}) - with self.assertWarns('order of the arguments'): + with pytest.deprecated_call(): actual = named.to_dataset('bar') self.assertDatasetIdentical(expected, actual) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index f098a0aabb8..c5f8668512b 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -274,7 +274,7 @@ class Arbitrary(object): self.assertDatasetIdentical(expected, actual) def test_constructor_deprecated(self): - with self.assertWarns('deprecated'): + with pytest.deprecated_call(): DataArray([1, 2, 3], coords={'x': [0, 1, 2]}) def test_constructor_auto_align(self): From 67bf208cfa7d5c9ce805ce7bb42309d8c481fcb2 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Wed, 24 May 2017 00:59:55 -0700 Subject: [PATCH 2/3] deprecated_call() -> warns(FutureWarning) --- xarray/tests/test_dataarray.py | 2 +- xarray/tests/test_dataset.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index efcd58cb09d..d237ac11aa7 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2321,7 +2321,7 @@ def test_to_dataset_whole(self): self.assertDatasetIdentical(expected, actual) expected = Dataset({'bar': ('x', [1, 2])}) - with pytest.deprecated_call(): + with pytest.warns(FutureWarning): actual = named.to_dataset('bar') self.assertDatasetIdentical(expected, actual) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index c5f8668512b..a889f2268e3 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -274,7 +274,7 @@ class Arbitrary(object): self.assertDatasetIdentical(expected, actual) def test_constructor_deprecated(self): - with pytest.deprecated_call(): + with pytest.warns(FutureWarning): DataArray([1, 2, 3], coords={'x': [0, 1, 2]}) def test_constructor_auto_align(self): From c3e64e135ded8cddbea28efddb45641bde6a1fbf Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Wed, 24 May 2017 01:25:10 -0700 Subject: [PATCH 3/3] another attempt --- xarray/tests/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/tests/__init__.py b/xarray/tests/__init__.py index be8a4277033..d9127b82d3f 100644 --- a/xarray/tests/__init__.py +++ b/xarray/tests/__init__.py @@ -1,6 +1,7 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function +import warnings from contextlib import contextmanager from distutils.version import LooseVersion @@ -118,7 +119,8 @@ def assertItemsEqual(self, first, second, msg=None): @contextmanager def assertWarns(self, message): - with pytest.warns(Warning) as w: + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always', message) yield assert len(w) > 0 assert any(message in str(wi.message) for wi in w)