Skip to content

Commit

Permalink
test_groupby: Clear recorded warnings for pytest-8 compatibility
Browse files Browse the repository at this point in the history
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 pydata#8681
  • Loading branch information
mgorny committed Jan 31, 2024
1 parent 306a50e commit 3bc5abf
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_groupby_dims_property(dataset, recwarn) -> None:
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
assert dataset.groupby("x").dims == dataset.isel(x=1).dims
assert dataset.groupby("y").dims == dataset.isel(y=1).dims
# in pytest-8, pytest.warns() no longer clears all warnings
recwarn.clear()

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

0 comments on commit 3bc5abf

Please sign in to comment.