Skip to content

Commit f7b0bd8

Browse files
Apply assorted ruff/flake8-pytest-style rules (PT) (#10363)
* Apply ruff/flake8-pytest-style rule PT001 PT001 Use `@pytest.fixture` over `@pytest.fixture()` Both are acceptable, the rule is about consistency. I chose `@pytest.fixture` (52 occurrences) over `@pytest.fixture()` (8 occurrences). * Apply ruff/flake8-pytest-style rule PT003 PT003 `scope='function'` is implied in `@pytest.fixture()` * Apply ruff/flake8-pytest-style rule PT017 PT017 Found assertion on exception in `except` block, use `pytest.raises()` instead
1 parent c303ffc commit f7b0bd8

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

xarray/tests/test_accessor_dt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ def calendar(request):
400400
return request.param
401401

402402

403-
@pytest.fixture()
403+
@pytest.fixture
404404
def cftime_date_type(calendar):
405405
if calendar == "standard":
406406
calendar = "proleptic_gregorian"
407407
return _all_cftime_date_types()[calendar]
408408

409409

410-
@pytest.fixture()
410+
@pytest.fixture
411411
def times(calendar):
412412
import cftime
413413

@@ -419,7 +419,7 @@ def times(calendar):
419419
)
420420

421421

422-
@pytest.fixture()
422+
@pytest.fixture
423423
def data(times):
424424
data = np.random.rand(10, 10, _NT)
425425
lons = np.linspace(0, 11, 10)
@@ -429,7 +429,7 @@ def data(times):
429429
)
430430

431431

432-
@pytest.fixture()
432+
@pytest.fixture
433433
def times_3d(times):
434434
lons = np.linspace(0, 11, 10)
435435
lats = np.linspace(0, 20, 10)

xarray/tests/test_coding_times.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def calendar(request):
805805
return request.param
806806

807807

808-
@pytest.fixture()
808+
@pytest.fixture
809809
def times(calendar):
810810
import cftime
811811

@@ -817,7 +817,7 @@ def times(calendar):
817817
)
818818

819819

820-
@pytest.fixture()
820+
@pytest.fixture
821821
def data(times):
822822
data = np.random.rand(2, 2, 4)
823823
lons = np.linspace(0, 11, 2)
@@ -827,7 +827,7 @@ def data(times):
827827
)
828828

829829

830-
@pytest.fixture()
830+
@pytest.fixture
831831
def times_3d(times):
832832
lons = np.linspace(0, 11, 2)
833833
lats = np.linspace(0, 20, 2)

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

xarray/tests/test_datatree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ def close(self):
23252325
self.closed = True
23262326

23272327

2328-
@pytest.fixture()
2328+
@pytest.fixture
23292329
def tree_and_closers():
23302330
tree = DataTree.from_dict({"/child/grandchild": None})
23312331
closers = {

xarray/tests/test_distributed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_dask_distributed_read_netcdf_integration_test(
220220
# fixture vendored from dask
221221
# heads-up, this is using quite private zarr API
222222
# https://github.com/dask/dask/blob/e04734b4d8959ba259801f2e2a490cb4ee8d891f/dask/tests/test_distributed.py#L338-L358
223-
@pytest.fixture(scope="function")
223+
@pytest.fixture
224224
def zarr(client):
225225
zarr_lib = pytest.importorskip("zarr")
226226
# Zarr-Python 3 lazily allocates a dedicated thread/IO loop

xarray/tests/test_formatting_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def childfree_tree(self, childfree_tree_factory):
231231
"""
232232
return childfree_tree_factory()
233233

234-
@pytest.fixture(scope="function")
234+
@pytest.fixture
235235
def mock_datatree_node_repr(self, monkeypatch):
236236
"""
237237
Apply mocking for datatree_node_repr.
@@ -245,7 +245,7 @@ def mock(group_title, dt):
245245

246246
monkeypatch.setattr(fh, "datatree_node_repr", mock)
247247

248-
@pytest.fixture(scope="function")
248+
@pytest.fixture
249249
def mock_wrap_datatree_repr(self, monkeypatch):
250250
"""
251251
Apply mocking for _wrap_datatree_repr.

xarray/tests/test_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def figure_context(*args, **kwargs):
6666
plt.close("all")
6767

6868

69-
@pytest.fixture(scope="function", autouse=True)
69+
@pytest.fixture(autouse=True)
7070
def test_all_figures_closed():
7171
"""meta-test to ensure all figures are closed at the end of a test
7272

0 commit comments

Comments
 (0)