Skip to content

Commit d30635c

Browse files
authored
Fix test suite use of str(exception) (#3059)
1 parent a78e0f6 commit d30635c

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,9 @@ Bug fixes
120120
By `Maximilian Roos <https://github.com/max-sixty>`_.
121121
- Fixed performance issues with cftime installed (:issue:`3000`)
122122
By `0x0L <https://github.com/0x0L>`_.
123-
- Replace incorrect usages of `message` in pytest assertions
124-
with `match` (:issue:`3011`)
125-
By `Maximilian Roos <https://github.com/max-sixty>`_.
126-
- Add explicit pytest markers, now required by pytest
127-
(:issue:`3032`).
128-
By `Maximilian Roos <https://github.com/max-sixty>`_.
123+
- Test suite fixes for newer versions of pytest (:issue:`3011`, :issue:`3032`).
124+
By `Maximilian Roos <https://github.com/max-sixty>`_
125+
and `Stephan Hoyer <https://github.com/shoyer>`_.
129126

130127
.. _whats-new.0.12.1:
131128

xarray/tests/test_dataarray.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,15 +3710,14 @@ def test_rolling_properties(da):
37103710
assert rolling_obj.obj.get_axis_num('time') == 1
37113711

37123712
# catching invalid args
3713-
with pytest.raises(ValueError) as exception:
3713+
with pytest.raises(ValueError, match='exactly one dim/window should'):
37143714
da.rolling(time=7, x=2)
3715-
assert 'exactly one dim/window should' in str(exception)
3716-
with pytest.raises(ValueError) as exception:
3715+
with pytest.raises(ValueError, match='window must be > 0'):
37173716
da.rolling(time=-2)
3718-
assert 'window must be > 0' in str(exception)
3719-
with pytest.raises(ValueError) as exception:
3717+
with pytest.raises(
3718+
ValueError, match='min_periods must be greater than zero'
3719+
):
37203720
da.rolling(time=2, min_periods=0)
3721-
assert 'min_periods must be greater than zero' in str(exception)
37223721

37233722

37243723
@pytest.mark.parametrize('name', ('sum', 'mean', 'std', 'min', 'max',

xarray/tests/test_dataset.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,18 +4788,16 @@ def test_coarsen_coords_cftime():
47884788

47894789
def test_rolling_properties(ds):
47904790
# catching invalid args
4791-
with pytest.raises(ValueError) as exception:
4791+
with pytest.raises(ValueError, match='exactly one dim/window should'):
47924792
ds.rolling(time=7, x=2)
4793-
assert 'exactly one dim/window should' in str(exception)
4794-
with pytest.raises(ValueError) as exception:
4793+
with pytest.raises(ValueError, match='window must be > 0'):
47954794
ds.rolling(time=-2)
4796-
assert 'window must be > 0' in str(exception)
4797-
with pytest.raises(ValueError) as exception:
4795+
with pytest.raises(
4796+
ValueError, match='min_periods must be greater than zero'
4797+
):
47984798
ds.rolling(time=2, min_periods=0)
4799-
assert 'min_periods must be greater than zero' in str(exception)
4800-
with pytest.raises(KeyError) as exception:
4799+
with pytest.raises(KeyError, match='time2'):
48014800
ds.rolling(time2=2)
4802-
assert 'time2' in str(exception)
48034801

48044802

48054803
@pytest.mark.parametrize('name',

0 commit comments

Comments
 (0)