diff --git a/zarr/storage.py b/zarr/storage.py index 2452cc5f1c..582ecfe7e2 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -7,6 +7,7 @@ import zipfile import shutil import atexit +import warnings import numpy as np @@ -830,7 +831,9 @@ def __setitem__(self, key, value): if self.mode == 'r': err_read_only() value = ensure_bytes(value) - self.zf.writestr(key, value) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + self.zf.writestr(key, value) def __delitem__(self, key): raise NotImplementedError diff --git a/zarr/tests/test_storage.py b/zarr/tests/test_storage.py index bf03c96a21..24240068fa 100644 --- a/zarr/tests/test_storage.py +++ b/zarr/tests/test_storage.py @@ -8,6 +8,7 @@ import array import shutil import os +import warnings import numpy as np @@ -645,6 +646,21 @@ def test_mode(self): with assert_raises(PermissionError): store['foo'] = b'bar' + def test_duplicate(self): + caught = False + with warnings.catch_warnings(): + warnings.simplefilter("error", UserWarning) + try: + with ZipStore('example.zip', mode='w') as store: + store['foo'] = b'bar' + store['foo'] = b'baz' + except UserWarning: + caught = False + else: + caught = True + + self.assertTrue(caught, "Failed to catch UserWarning.") + def test_getsize(): store = dict()