Skip to content

Commit 53d6b42

Browse files
workaround for pytest marker stains bug pytest-dev/pytest#568
1 parent 7d69d7b commit 53d6b42

File tree

4 files changed

+140
-138
lines changed

4 files changed

+140
-138
lines changed

zarr/tests/test_convenience.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -579,42 +579,38 @@ def test_logging(self):
579579
h5py = None
580580

581581

582-
def temp_h5f():
583-
fn = tempfile.mktemp()
584-
atexit.register(os.remove, fn)
585-
h5f = h5py.File(fn, mode='w')
586-
atexit.register(lambda v: v.close(), h5f)
587-
return h5f
582+
if h5py is not None:
588583

589-
590-
@pytest.mark.skipif(h5py is None, reason='h5py not installed')
591-
class TestCopyHDF5ToZarr(TestCopy):
592-
593-
def __init__(self, *args, **kwargs):
594-
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
595-
self.source_h5py = True
596-
self.dest_h5py = False
597-
self.new_source = temp_h5f
598-
self.new_dest = group
599-
600-
601-
@pytest.mark.skipif(h5py is None, reason='h5py not installed')
602-
class TestCopyZarrToHDF5(TestCopy):
603-
604-
def __init__(self, *args, **kwargs):
605-
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
606-
self.source_h5py = False
607-
self.dest_h5py = True
608-
self.new_source = group
609-
self.new_dest = temp_h5f
610-
611-
612-
@pytest.mark.skipif(h5py is None, reason='h5py not installed')
613-
class TestCopyHDF5ToHDF5(TestCopy):
614-
615-
def __init__(self, *args, **kwargs):
616-
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
617-
self.source_h5py = True
618-
self.dest_h5py = True
619-
self.new_source = temp_h5f
620-
self.new_dest = temp_h5f
584+
def temp_h5f():
585+
fn = tempfile.mktemp()
586+
atexit.register(os.remove, fn)
587+
h5f = h5py.File(fn, mode='w')
588+
atexit.register(lambda v: v.close(), h5f)
589+
return h5f
590+
591+
class TestCopyHDF5ToZarr(TestCopy):
592+
593+
def __init__(self, *args, **kwargs):
594+
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
595+
self.source_h5py = True
596+
self.dest_h5py = False
597+
self.new_source = temp_h5f
598+
self.new_dest = group
599+
600+
class TestCopyZarrToHDF5(TestCopy):
601+
602+
def __init__(self, *args, **kwargs):
603+
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
604+
self.source_h5py = False
605+
self.dest_h5py = True
606+
self.new_source = group
607+
self.new_dest = temp_h5f
608+
609+
class TestCopyHDF5ToHDF5(TestCopy):
610+
611+
def __init__(self, *args, **kwargs):
612+
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
613+
self.source_h5py = True
614+
self.dest_h5py = True
615+
self.new_source = temp_h5f
616+
self.new_dest = temp_h5f

zarr/tests/test_core.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,23 +1251,24 @@ def test_nbytes_stored(self):
12511251
bsddb3 = None
12521252

12531253

1254-
@pytest.mark.skipif(bsddb3 is None, reason='bsddb3 not installed')
1255-
class TestArrayWithDBMStoreBerkeleyDB(TestArray):
1254+
if bsddb3 is not None:
12561255

1257-
@staticmethod
1258-
def create_array(read_only=False, **kwargs):
1259-
path = mktemp(suffix='.dbm')
1260-
atexit.register(os.remove, path)
1261-
store = DBMStore(path, flag='n', open=bsddb3.btopen)
1262-
cache_metadata = kwargs.pop('cache_metadata', True)
1263-
cache_attrs = kwargs.pop('cache_attrs', True)
1264-
kwargs.setdefault('compressor', Zlib(1))
1265-
init_array(store, **kwargs)
1266-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1267-
cache_attrs=cache_attrs)
1256+
class TestArrayWithDBMStoreBerkeleyDB(TestArray):
12681257

1269-
def test_nbytes_stored(self):
1270-
pass # not implemented
1258+
@staticmethod
1259+
def create_array(read_only=False, **kwargs):
1260+
path = mktemp(suffix='.dbm')
1261+
atexit.register(os.remove, path)
1262+
store = DBMStore(path, flag='n', open=bsddb3.btopen)
1263+
cache_metadata = kwargs.pop('cache_metadata', True)
1264+
cache_attrs = kwargs.pop('cache_attrs', True)
1265+
kwargs.setdefault('compressor', Zlib(1))
1266+
init_array(store, **kwargs)
1267+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1268+
cache_attrs=cache_attrs)
1269+
1270+
def test_nbytes_stored(self):
1271+
pass # not implemented
12711272

12721273

12731274
try:
@@ -1276,42 +1277,41 @@ def test_nbytes_stored(self):
12761277
lmdb = None
12771278

12781279

1279-
@pytest.mark.skipif(lmdb is None, reason='lmdb is not installed')
1280-
class TestArrayWithLMDBStore(TestArray):
1280+
if lmdb is not None:
12811281

1282-
@staticmethod
1283-
def create_array(read_only=False, **kwargs):
1284-
path = mktemp(suffix='.lmdb')
1285-
atexit.register(atexit_rmtree, path)
1286-
store = LMDBStore(path, buffers=True)
1287-
cache_metadata = kwargs.pop('cache_metadata', True)
1288-
cache_attrs = kwargs.pop('cache_attrs', True)
1289-
kwargs.setdefault('compressor', Zlib(1))
1290-
init_array(store, **kwargs)
1291-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1292-
cache_attrs=cache_attrs)
1282+
class TestArrayWithLMDBStore(TestArray):
12931283

1294-
def test_nbytes_stored(self):
1295-
pass # not implemented
1284+
@staticmethod
1285+
def create_array(read_only=False, **kwargs):
1286+
path = mktemp(suffix='.lmdb')
1287+
atexit.register(atexit_rmtree, path)
1288+
store = LMDBStore(path, buffers=True)
1289+
cache_metadata = kwargs.pop('cache_metadata', True)
1290+
cache_attrs = kwargs.pop('cache_attrs', True)
1291+
kwargs.setdefault('compressor', Zlib(1))
1292+
init_array(store, **kwargs)
1293+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1294+
cache_attrs=cache_attrs)
12961295

1296+
def test_nbytes_stored(self):
1297+
pass # not implemented
12971298

1298-
@pytest.mark.skipif(lmdb is None, reason='lmdb is not installed')
1299-
class TestArrayWithLMDBStoreNoBuffers(TestArray):
1299+
class TestArrayWithLMDBStoreNoBuffers(TestArray):
13001300

1301-
@staticmethod
1302-
def create_array(read_only=False, **kwargs):
1303-
path = mktemp(suffix='.lmdb')
1304-
atexit.register(atexit_rmtree, path)
1305-
store = LMDBStore(path, buffers=False)
1306-
cache_metadata = kwargs.pop('cache_metadata', True)
1307-
cache_attrs = kwargs.pop('cache_attrs', True)
1308-
kwargs.setdefault('compressor', Zlib(1))
1309-
init_array(store, **kwargs)
1310-
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1311-
cache_attrs=cache_attrs)
1301+
@staticmethod
1302+
def create_array(read_only=False, **kwargs):
1303+
path = mktemp(suffix='.lmdb')
1304+
atexit.register(atexit_rmtree, path)
1305+
store = LMDBStore(path, buffers=False)
1306+
cache_metadata = kwargs.pop('cache_metadata', True)
1307+
cache_attrs = kwargs.pop('cache_attrs', True)
1308+
kwargs.setdefault('compressor', Zlib(1))
1309+
init_array(store, **kwargs)
1310+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
1311+
cache_attrs=cache_attrs)
13121312

1313-
def test_nbytes_stored(self):
1314-
pass # not implemented
1313+
def test_nbytes_stored(self):
1314+
pass # not implemented
13151315

13161316

13171317
class TestArrayWithNoCompressor(TestArray):

zarr/tests/test_hierarchy.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,16 @@ def create_store():
892892
bsddb3 = None
893893

894894

895-
@pytest.mark.skipif(bsddb3 is None, reason='bsddb3 is not installed')
896-
class TestGroupWithDBMStoreBerkeleyDB(TestGroup):
895+
if bsddb3 is not None:
897896

898-
@staticmethod
899-
def create_store():
900-
path = tempfile.mktemp(suffix='.dbm')
901-
atexit.register(os.remove, path)
902-
store = DBMStore(path, flag='n', open=bsddb3.btopen)
903-
return store, None
897+
class TestGroupWithDBMStoreBerkeleyDB(TestGroup):
898+
899+
@staticmethod
900+
def create_store():
901+
path = tempfile.mktemp(suffix='.dbm')
902+
atexit.register(os.remove, path)
903+
store = DBMStore(path, flag='n', open=bsddb3.btopen)
904+
return store, None
904905

905906

906907
try:
@@ -909,15 +910,16 @@ def create_store():
909910
lmdb = None
910911

911912

912-
@pytest.mark.skipif(lmdb is None, reason='lmdb is not installed')
913-
class TestGroupWithLMDBStore(TestGroup):
913+
if lmdb is not None:
914914

915-
@staticmethod
916-
def create_store():
917-
path = tempfile.mktemp(suffix='.lmdb')
918-
atexit.register(atexit_rmtree, path)
919-
store = LMDBStore(path)
920-
return store, None
915+
class TestGroupWithLMDBStore(TestGroup):
916+
917+
@staticmethod
918+
def create_store():
919+
path = tempfile.mktemp(suffix='.lmdb')
920+
atexit.register(atexit_rmtree, path)
921+
store = LMDBStore(path)
922+
return store, None
921923

922924

923925
class TestGroupWithChunkStore(TestGroup):

zarr/tests/test_storage.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,15 @@ def create_store(self):
777777
gdbm = None
778778

779779

780-
@pytest.mark.skipif(gdbm is None, reason='gdbm is not installed')
781-
class TestDBMStoreGnu(TestDBMStore):
780+
if gdbm is not None:
782781

783-
def create_store(self):
784-
path = tempfile.mktemp(suffix='.gdbm')
785-
atexit.register(os.remove, path)
786-
store = DBMStore(path, flag='n', open=gdbm.open, write_lock=False)
787-
return store
782+
class TestDBMStoreGnu(TestDBMStore):
783+
784+
def create_store(self):
785+
path = tempfile.mktemp(suffix='.gdbm')
786+
atexit.register(os.remove, path)
787+
store = DBMStore(path, flag='n', open=gdbm.open, write_lock=False)
788+
return store
788789

789790

790791
if not PY2:
@@ -793,14 +794,15 @@ def create_store(self):
793794
except ImportError: # pragma: no cover
794795
ndbm = None
795796

796-
@pytest.mark.skipif(ndbm is None, reason='ndbm is not installed')
797-
class TestDBMStoreNDBM(TestDBMStore):
797+
if ndbm is not None:
798798

799-
def create_store(self):
800-
path = tempfile.mktemp(suffix='.ndbm')
801-
atexit.register(atexit_rmglob, path + '*')
802-
store = DBMStore(path, flag='n', open=ndbm.open)
803-
return store
799+
class TestDBMStoreNDBM(TestDBMStore):
800+
801+
def create_store(self):
802+
path = tempfile.mktemp(suffix='.ndbm')
803+
atexit.register(atexit_rmglob, path + '*')
804+
store = DBMStore(path, flag='n', open=ndbm.open)
805+
return store
804806

805807

806808
try:
@@ -809,14 +811,15 @@ def create_store(self):
809811
bsddb3 = None
810812

811813

812-
@pytest.mark.skipif(bsddb3 is None, reason='bsddb3 is not installed')
813-
class TestDBMStoreBerkeleyDB(TestDBMStore):
814+
if bsddb3 is not None:
814815

815-
def create_store(self):
816-
path = tempfile.mktemp(suffix='.dbm')
817-
atexit.register(os.remove, path)
818-
store = DBMStore(path, flag='n', open=bsddb3.btopen, write_lock=False)
819-
return store
816+
class TestDBMStoreBerkeleyDB(TestDBMStore):
817+
818+
def create_store(self):
819+
path = tempfile.mktemp(suffix='.dbm')
820+
atexit.register(os.remove, path)
821+
store = DBMStore(path, flag='n', open=bsddb3.btopen, write_lock=False)
822+
return store
820823

821824

822825
try:
@@ -825,26 +828,27 @@ def create_store(self):
825828
lmdb = None
826829

827830

828-
@pytest.mark.skipif(lmdb is None, reason='lmdb is not installed')
829-
class TestLMDBStore(StoreTests, unittest.TestCase):
831+
if lmdb is not None:
830832

831-
def create_store(self):
832-
path = tempfile.mktemp(suffix='.lmdb')
833-
atexit.register(atexit_rmtree, path)
834-
if PY2: # pragma: py3 no cover
835-
# don't use buffers, otherwise would have to rewrite tests as bytes and
836-
# buffer don't compare equal in PY2
837-
buffers = False
838-
else: # pragma: py2 no cover
839-
buffers = True
840-
store = LMDBStore(path, buffers=buffers)
841-
return store
833+
class TestLMDBStore(StoreTests, unittest.TestCase):
842834

843-
def test_context_manager(self):
844-
with self.create_store() as store:
845-
store['foo'] = b'bar'
846-
store['baz'] = b'qux'
847-
assert 2 == len(store)
835+
def create_store(self):
836+
path = tempfile.mktemp(suffix='.lmdb')
837+
atexit.register(atexit_rmtree, path)
838+
if PY2: # pragma: py3 no cover
839+
# don't use buffers, otherwise would have to rewrite tests as bytes and
840+
# buffer don't compare equal in PY2
841+
buffers = False
842+
else: # pragma: py2 no cover
843+
buffers = True
844+
store = LMDBStore(path, buffers=buffers)
845+
return store
846+
847+
def test_context_manager(self):
848+
with self.create_store() as store:
849+
store['foo'] = b'bar'
850+
store['baz'] = b'qux'
851+
assert 2 == len(store)
848852

849853

850854
class TestLRUStoreCache(StoreTests, unittest.TestCase):

0 commit comments

Comments
 (0)