Skip to content

Apply assorted ruff/flake8-pytest-style rules (PT) #10363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions xarray/tests/test_accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@ def calendar(request):
return request.param


@pytest.fixture()
@pytest.fixture
def cftime_date_type(calendar):
if calendar == "standard":
calendar = "proleptic_gregorian"
return _all_cftime_date_types()[calendar]


@pytest.fixture()
@pytest.fixture
def times(calendar):
import cftime

Expand All @@ -419,7 +419,7 @@ def times(calendar):
)


@pytest.fixture()
@pytest.fixture
def data(times):
data = np.random.rand(10, 10, _NT)
lons = np.linspace(0, 11, 10)
Expand All @@ -429,7 +429,7 @@ def data(times):
)


@pytest.fixture()
@pytest.fixture
def times_3d(times):
lons = np.linspace(0, 11, 10)
lats = np.linspace(0, 20, 10)
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def calendar(request):
return request.param


@pytest.fixture()
@pytest.fixture
def times(calendar):
import cftime

Expand All @@ -817,7 +817,7 @@ def times(calendar):
)


@pytest.fixture()
@pytest.fixture
def data(times):
data = np.random.rand(2, 2, 4)
lons = np.linspace(0, 11, 2)
Expand All @@ -827,7 +827,7 @@ def data(times):
)


@pytest.fixture()
@pytest.fixture
def times_3d(times):
lons = np.linspace(0, 11, 2)
lats = np.linspace(0, 20, 2)
Expand Down
8 changes: 2 additions & 6 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,10 @@ def test_concat(self):

def test_missing_methods(self):
v = self.lazy_var
try:
with pytest.raises(NotImplementedError, match="dask"):
v.argsort()
except NotImplementedError as err:
assert "dask" in str(err)
try:
with pytest.raises(NotImplementedError, match="dask"):
v[0].item()
except NotImplementedError as err:
assert "dask" in str(err)

def test_univariate_ufunc(self):
u = self.eager_var
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ def close(self):
self.closed = True


@pytest.fixture()
@pytest.fixture
def tree_and_closers():
tree = DataTree.from_dict({"/child/grandchild": None})
closers = {
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_dask_distributed_read_netcdf_integration_test(
# fixture vendored from dask
# heads-up, this is using quite private zarr API
# https://github.com/dask/dask/blob/e04734b4d8959ba259801f2e2a490cb4ee8d891f/dask/tests/test_distributed.py#L338-L358
@pytest.fixture(scope="function")
@pytest.fixture
def zarr(client):
zarr_lib = pytest.importorskip("zarr")
# Zarr-Python 3 lazily allocates a dedicated thread/IO loop
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def childfree_tree(self, childfree_tree_factory):
"""
return childfree_tree_factory()

@pytest.fixture(scope="function")
@pytest.fixture
def mock_datatree_node_repr(self, monkeypatch):
"""
Apply mocking for datatree_node_repr.
Expand All @@ -245,7 +245,7 @@ def mock(group_title, dt):

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

@pytest.fixture(scope="function")
@pytest.fixture
def mock_wrap_datatree_repr(self, monkeypatch):
"""
Apply mocking for _wrap_datatree_repr.
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def figure_context(*args, **kwargs):
plt.close("all")


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

Expand Down
Loading