Skip to content

Commit 50abf3d

Browse files
authored
Clean up warning filters in tests (#2714)
* Clean up warning filters in tests * Ignore some more warnings * Ignore some more warnings * Ignore boto3 deprecation warning * Ignore unclosed client warning * Filter another fsspec warning * Ignore zip warning * Filter warning in test_stateful * pre-commit fixes * Filter warning in test_wrapper * Filter warning in memorystore * Close pool in multiprocessing test * pre-commit fixes * Filter two more warnings * Filter another warning * Filter more warnings * Add changelog * Ignore unclosed client sessions * Put back dtype filter * Make client session filter better
1 parent 3b6565b commit 50abf3d

9 files changed

+59
-10
lines changed

changes/2714.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make warning filters in the tests more specific, so warnings emitted by tests added in the future are more likely to be caught instead of ignored.

pyproject.toml

+12-6
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,18 @@ addopts = [
397397
"--durations=10", "-ra", "--strict-config", "--strict-markers",
398398
]
399399
filterwarnings = [
400-
"error:::zarr.*",
401-
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning",
402-
"ignore:The loop argument is deprecated since Python 3.8.*:DeprecationWarning",
403-
"ignore:Creating a zarr.buffer.gpu.*:UserWarning",
404-
"ignore:Duplicate name:UserWarning", # from ZipFile
405-
"ignore:.*is currently not part in the Zarr format 3 specification.*:UserWarning",
400+
"error",
401+
# TODO: explicitly filter or catch the warnings below where we expect them to be emitted in the tests
402+
"ignore:Consolidated metadata is currently not part in the Zarr format 3 specification.*:UserWarning",
403+
"ignore:Creating a zarr.buffer.gpu.Buffer with an array that does not support the __cuda_array_interface__.*:UserWarning",
404+
"ignore:Automatic shard shape inference is experimental and may change without notice.*:UserWarning",
405+
"ignore:The codec .* is currently not part in the Zarr format 3 specification.*:UserWarning",
406+
"ignore:The dtype .* is currently not part in the Zarr format 3 specification.*:UserWarning",
407+
"ignore:Use zarr.create_array instead.:DeprecationWarning",
408+
"ignore:Duplicate name.*:UserWarning",
409+
"ignore:The `compressor` argument is deprecated. Use `compressors` instead.:UserWarning",
410+
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.:UserWarning",
411+
"ignore:Unclosed client session <aiohttp.client.ClientSession.*:ResourceWarning"
406412
]
407413
markers = [
408414
"gpu: mark a test as requiring CuPy and GPU",

tests/test_array.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1417,9 +1417,8 @@ def test_multiprocessing(store: Store, method: Literal["fork", "spawn", "forkser
14171417
data = np.arange(100)
14181418
arr = zarr.create_array(store=store, data=data)
14191419
ctx = mp.get_context(method)
1420-
pool = ctx.Pool()
1421-
1422-
results = pool.starmap(_index_array, [(arr, slice(len(data)))])
1420+
with ctx.Pool() as pool:
1421+
results = pool.starmap(_index_array, [(arr, slice(len(data)))])
14231422
assert all(np.array_equal(r, data) for r in results)
14241423

14251424

tests/test_store/test_fsspec.py

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import re
56
from typing import TYPE_CHECKING
67

78
import pytest
@@ -19,6 +20,17 @@
1920

2021
import botocore.client
2122

23+
# Warning filter due to https://github.com/boto/boto3/issues/3889
24+
pytestmark = [
25+
pytest.mark.filterwarnings(
26+
re.escape("ignore:datetime.datetime.utcnow() is deprecated:DeprecationWarning")
27+
),
28+
# TODO: fix these warnings
29+
pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning"),
30+
pytest.mark.filterwarnings(
31+
"ignore:coroutine 'ClientCreatorContext.__aexit__' was never awaited:RuntimeWarning"
32+
),
33+
]
2234

2335
fsspec = pytest.importorskip("fsspec")
2436
s3fs = pytest.importorskip("s3fs")

tests/test_store/test_memory.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from typing import TYPE_CHECKING
45

56
import numpy as np
@@ -15,6 +16,10 @@
1516
from zarr.core.common import ZarrFormat
1617

1718

19+
# TODO: work out where this warning is coming from and fix it
20+
@pytest.mark.filterwarnings(
21+
re.escape("ignore:coroutine 'ClientCreatorContext.__aexit__' was never awaited")
22+
)
1823
class TestMemoryStore(StoreTests[MemoryStore, cpu.Buffer]):
1924
store_cls = MemoryStore
2025
buffer_cls = cpu.Buffer
@@ -73,6 +78,8 @@ async def test_deterministic_size(
7378
np.testing.assert_array_equal(a[3:], 0)
7479

7580

81+
# TODO: fix this warning
82+
@pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning")
7683
@gpu_test
7784
class TestGpuMemoryStore(StoreTests[GpuMemoryStore, gpu.Buffer]):
7885
store_cls = GpuMemoryStore

tests/test_store/test_stateful.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from zarr.storage import LocalStore, ZipStore
99
from zarr.testing.stateful import ZarrHierarchyStateMachine, ZarrStoreStateMachine
1010

11-
pytestmark = pytest.mark.slow_hypothesis
11+
pytestmark = [
12+
pytest.mark.slow_hypothesis,
13+
# TODO: work out where this warning is coming from and fix
14+
pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning"),
15+
]
1216

1317

1418
def test_zarr_hierarchy(sync_store: Store):

tests/test_store/test_wrapper.py

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
from zarr.core.buffer.core import BufferPrototype
1616

1717

18+
# TODO: fix this warning
19+
@pytest.mark.filterwarnings(
20+
"ignore:coroutine 'ClientCreatorContext.__aexit__' was never awaited:RuntimeWarning"
21+
)
1822
class TestWrapperStore(StoreTests[WrapperStore, Buffer]):
1923
store_cls = WrapperStore
2024
buffer_cls = Buffer
@@ -72,6 +76,10 @@ def test_is_open_setter_raises(self, store: WrapperStore) -> None:
7276
store._is_open = True
7377

7478

79+
# TODO: work out where warning is coming from and fix
80+
@pytest.mark.filterwarnings(
81+
"ignore:coroutine 'ClientCreatorContext.__aexit__' was never awaited:RuntimeWarning"
82+
)
7583
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True)
7684
async def test_wrapped_set(store: Store, capsys: pytest.CaptureFixture[str]) -> None:
7785
# define a class that prints when it sets
@@ -89,6 +97,7 @@ async def set(self, key: str, value: Buffer) -> None:
8997
assert await store_wrapped.get(key, buffer_prototype) == value
9098

9199

100+
@pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning")
92101
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=True)
93102
async def test_wrapped_get(store: Store, capsys: pytest.CaptureFixture[str]) -> None:
94103
# define a class that prints when it sets

tests/test_store/test_zip.py

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
from typing import Any
2020

2121

22+
# TODO: work out where this is coming from and fix
23+
pytestmark = [
24+
pytest.mark.filterwarnings(
25+
"ignore:coroutine method 'aclose' of 'ZipStore.list' was never awaited:RuntimeWarning"
26+
)
27+
]
28+
29+
2230
class TestZipStore(StoreTests[ZipStore, cpu.Buffer]):
2331
store_cls = ZipStore
2432
buffer_cls = cpu.Buffer
@@ -66,6 +74,8 @@ def test_store_supports_partial_writes(self, store: ZipStore) -> None:
6674
def test_store_supports_listing(self, store: ZipStore) -> None:
6775
assert store.supports_listing
6876

77+
# TODO: fix this warning
78+
@pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning")
6979
def test_api_integration(self, store: ZipStore) -> None:
7080
root = zarr.open_group(store=store, mode="a")
7181

tests/test_sync.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def test_sync_raises_if_loop_is_closed() -> None:
9090
foo.assert_not_awaited()
9191

9292

93+
@pytest.mark.filterwarnings("ignore:Unclosed client session:ResourceWarning")
9394
@pytest.mark.filterwarnings("ignore:coroutine.*was never awaited")
9495
def test_sync_raises_if_calling_sync_from_within_a_running_loop(
9596
sync_loop: asyncio.AbstractEventLoop | None,

0 commit comments

Comments
 (0)