Skip to content

Commit ca10531

Browse files
authored
Fixes for pytest-8.0.0 compatibility (#8686)
* test_dataset: remove incorrect pytest.warns() to fix pytest-8 Remove two incorrect `pytest.warns()` assertions to fix test failures with pytest-8.0.0. Prior to this version, an exception raised would cause `pytest.warns()` to be ignored. This way fixed in 8.0.0, and now warnings must actually be emitted prior to the exception. In `test_drop_index_labels()`, the exception is raised at the very beginning of the function, prior to the deprecation warning. In `test_rename_multiindex()`, the warning is not emitted at all (it is not applicable to the call in question). * test_groupby: Clear recorded warnings for pytest-8 compatibility Clear the warnings recorded during the `pytest.warns()` use in `test_groupby_dims_property`, to fix test failures with pytest-8.0.0. Prior to this version, `pytest.warns()` invocation used to capture all warnings. Now it only captures the warnings that match the arguments, and the remaining warnings are re-emitted and therefore caught by `recwarn` fixture. To provide compatibility with both versions of pytest, clear the recorded warnings immediately after `pytest.warns()`. Fixes #8681 * Revert "Fix CI: temporary pin pytest version to 7.4.* (#8682)" This reverts commit b0b5b2f. The tests should be fixed now.
1 parent 614c25b commit ca10531

File tree

9 files changed

+11
-11
lines changed

9 files changed

+11
-11
lines changed

ci/requirements/all-but-dask.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
- pint>=0.22
2828
- pip
2929
- pydap
30-
- pytest==7.4.*
30+
- pytest
3131
- pytest-cov
3232
- pytest-env
3333
- pytest-xdist

ci/requirements/bare-minimum.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python=3.9
77
- coveralls
88
- pip
9-
- pytest==7.4.*
9+
- pytest
1010
- pytest-cov
1111
- pytest-env
1212
- pytest-xdist

ci/requirements/environment-3.12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies:
3333
- pooch
3434
- pre-commit
3535
- pydap
36-
- pytest==7.4.*
36+
- pytest
3737
- pytest-cov
3838
- pytest-env
3939
- pytest-xdist

ci/requirements/environment-windows-3.12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies:
2828
- pip
2929
- pre-commit
3030
- pydap
31-
- pytest==7.4.*
31+
- pytest
3232
- pytest-cov
3333
- pytest-env
3434
- pytest-xdist

ci/requirements/environment-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies:
2828
- pip
2929
- pre-commit
3030
- pydap
31-
- pytest==7.4.*
31+
- pytest
3232
- pytest-cov
3333
- pytest-env
3434
- pytest-xdist

ci/requirements/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies:
3434
- pre-commit
3535
- pyarrow # pandas makes a deprecation warning without this, breaking doctests
3636
- pydap
37-
- pytest==7.4.*
37+
- pytest
3838
- pytest-cov
3939
- pytest-env
4040
- pytest-xdist

ci/requirements/min-all-deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies:
4242
- pint=0.22
4343
- pip
4444
- pydap=3.3
45-
- pytest==7.4.*
45+
- pytest
4646
- pytest-cov
4747
- pytest-env
4848
- pytest-xdist

xarray/tests/test_dataset.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,8 +2724,7 @@ def test_drop_index_labels(self) -> None:
27242724
assert_identical(data, actual)
27252725

27262726
with pytest.raises(ValueError):
2727-
with pytest.warns(DeprecationWarning):
2728-
data.drop(["c"], dim="x", errors="wrong_value") # type: ignore[arg-type]
2727+
data.drop(["c"], dim="x", errors="wrong_value") # type: ignore[arg-type]
27292728

27302729
with pytest.warns(DeprecationWarning):
27312730
actual = data.drop(["a", "b", "c"], "x", errors="ignore")
@@ -3159,8 +3158,7 @@ def test_rename_multiindex(self) -> None:
31593158
original.rename({"a": "x"})
31603159

31613160
with pytest.raises(ValueError, match=r"'b' conflicts"):
3162-
with pytest.warns(UserWarning, match="does not create an index anymore"):
3163-
original.rename({"a": "b"})
3161+
original.rename({"a": "b"})
31643162

31653163
def test_rename_perserve_attrs_encoding(self) -> None:
31663164
# test propagate attrs/encoding to new variable(s) created from Index object

xarray/tests/test_groupby.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def test_groupby_dims_property(dataset, recwarn) -> None:
6767
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
6868
assert dataset.groupby("x").dims == dataset.isel(x=1).dims
6969
assert dataset.groupby("y").dims == dataset.isel(y=1).dims
70+
# in pytest-8, pytest.warns() no longer clears all warnings
71+
recwarn.clear()
7072

7173
# when squeeze=False, no warning should be raised
7274
assert tuple(dataset.groupby("x", squeeze=False).dims) == tuple(

0 commit comments

Comments
 (0)