From 8cc553259000cb0a024e9539efb3d1896bf1b221 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 10 Jun 2019 14:44:36 -0400 Subject: [PATCH 1/3] Pytest uses match, not message --- xarray/tests/test_dataarray.py | 4 ++-- xarray/tests/test_dataset.py | 10 +++++----- xarray/tests/test_plot.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 3580155781a..68421d96b1b 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -1177,7 +1177,7 @@ def test_reset_coords(self): dims=['x', 'y'], name='foo') assert_identical(actual, expected) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): with raises_regex(ValueError, 'cannot reset coord'): data = data.reset_coords(inplace=True) with raises_regex(ValueError, 'cannot be found'): @@ -1540,7 +1540,7 @@ def test_reorder_levels(self): obj = self.mda.reorder_levels(x=['level_2', 'level_1']) assert_identical(obj, expected) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): array = self.mda.copy() array.reorder_levels(x=['level_2', 'level_1'], inplace=True) assert_identical(array, expected) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index ecacf43caf4..068835c3a9f 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -2258,7 +2258,7 @@ def test_set_index(self): obj = ds.set_index(x=mindex.names) assert_identical(obj, expected) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): ds.set_index(x=mindex.names, inplace=True) assert_identical(ds, expected) @@ -2278,7 +2278,7 @@ def test_reset_index(self): obj = ds.reset_index('x') assert_identical(obj, expected) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): ds.reset_index('x', inplace=True) assert_identical(ds, expected) @@ -2291,7 +2291,7 @@ def test_reorder_levels(self): reindexed = ds.reorder_levels(x=['level_2', 'level_1']) assert_identical(reindexed, expected) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): ds.reorder_levels(x=['level_2', 'level_1'], inplace=True) assert_identical(ds, expected) @@ -2375,7 +2375,7 @@ def test_update(self): assert actual_result is actual assert_identical(expected, actual) - with pytest.warns(FutureWarning, message='The inplace argument'): + with pytest.warns(FutureWarning, match='The inplace argument'): actual = data.update(data, inplace=False) expected = data assert actual is not expected @@ -4615,7 +4615,7 @@ def test_dataset_constructor_aligns_to_explicit_coords( def test_error_message_on_set_supplied(): - with pytest.raises(TypeError, message='has invalid type set'): + with pytest.raises(TypeError, match='has invalid type set'): xr.Dataset(dict(date=[1, 2, 3], sec={4})) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 84510da65fe..25dc08a5602 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -210,7 +210,7 @@ def test_2d_coords_line_plot(self): hdl = da.plot.line(x='lon', hue='y') assert len(hdl) == 4 - with pytest.raises(ValueError, message='If x or y are 2D '): + with pytest.raises(ValueError, match='If x or y are 2D '): da.plot.line(x='lon', hue='lat') def test_2d_before_squeeze(self): From 875516b88465c3a268647bf883199f5da9314965 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 10 Jun 2019 15:23:26 -0400 Subject: [PATCH 2/3] correct messages --- xarray/tests/test_dataset.py | 2 +- xarray/tests/test_plot.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 068835c3a9f..dd7d2a98333 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -4615,7 +4615,7 @@ def test_dataset_constructor_aligns_to_explicit_coords( def test_error_message_on_set_supplied(): - with pytest.raises(TypeError, match='has invalid type set'): + with pytest.raises(TypeError, match="has invalid type "): xr.Dataset(dict(date=[1, 2, 3], sec={4})) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 25dc08a5602..a79becb3bda 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -210,7 +210,8 @@ def test_2d_coords_line_plot(self): hdl = da.plot.line(x='lon', hue='y') assert len(hdl) == 4 - with pytest.raises(ValueError, match='If x or y are 2D '): + with pytest.raises( + ValueError, match="For 2D inputs, hue must be a dimension"): da.plot.line(x='lon', hue='lat') def test_2d_before_squeeze(self): From dc07f4a4cb5a7a137e5fbe801172e508ffb141d4 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 11 Jun 2019 01:01:12 -0400 Subject: [PATCH 3/3] whatsnew --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index f397178ca5d..b01c53e76e2 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -76,6 +76,9 @@ Bug fixes By `Maximilian Roos `_. - Fixed performance issues with cftime installed (:issue:`3000`) By `0x0L `_. +- Replace incorrect usages of `message` in pytest assertions + with `match` (:issue:`3011`) + By `Maximilian Roos `_. .. _whats-new.0.12.1: