Skip to content

Commit e530f8d

Browse files
Apply ruff/flake8-pytest-style rule PT017
PT017 Found assertion on exception in `except` block, use `pytest.raises()` instead
1 parent 2f044c0 commit e530f8d

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

xarray/tests/test_backends.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,10 +2072,8 @@ def test_unsorted_index_raises(self) -> None:
20722072
ds2 = ondisk.isel(dim1=inds)
20732073
# Older versions of NetCDF4 raise an exception here, and if so we
20742074
# want to ensure we improve (that is, replace) the error message
2075-
try:
2075+
with pytest.raises(IndexError, match="first by calling .load"):
20762076
_ = ds2.randovar.values
2077-
except IndexError as err:
2078-
assert "first by calling .load" in str(err)
20792077

20802078
def test_setncattr_string(self) -> None:
20812079
list_of_strings = ["list", "of", "strings"]

xarray/tests/test_dask.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,10 @@ def test_concat(self):
255255

256256
def test_missing_methods(self):
257257
v = self.lazy_var
258-
try:
258+
with pytest.raises(NotImplementedError, match="dask"):
259259
v.argsort()
260-
except NotImplementedError as err:
261-
assert "dask" in str(err)
262-
try:
260+
with pytest.raises(NotImplementedError, match="dask"):
263261
v[0].item()
264-
except NotImplementedError as err:
265-
assert "dask" in str(err)
266262

267263
def test_univariate_ufunc(self):
268264
u = self.eager_var

0 commit comments

Comments
 (0)