Skip to content

Commit

Permalink
Pytest capture uses match, not message (#3011)
Browse files Browse the repository at this point in the history
* Pytest uses match, not message

* correct messages

* whatsnew
  • Loading branch information
max-sixty authored Jun 11, 2019
1 parent 43834ac commit f3efb5b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Bug fixes
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Fixed performance issues with cftime installed (:issue:`3000`)
By `0x0L <https://github.com/0x0L>`_.
- Replace incorrect usages of `message` in pytest assertions
with `match` (:issue:`3011`)
By `Maximilian Roos <https://github.com/max-sixty>`_.

.. _whats-new.0.12.1:

Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <class 'set'>"):
xr.Dataset(dict(date=[1, 2, 3], sec={4}))


Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, message='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):
Expand Down

0 comments on commit f3efb5b

Please sign in to comment.