File tree Expand file tree Collapse file tree 2 files changed +32
-16
lines changed
key-value-aio/tests/stores/rocksdb
key-value-sync/tests/code_gen/stores/rocksdb Expand file tree Collapse file tree 2 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 11import json
2- from collections .abc import AsyncGenerator
32from pathlib import Path
43from tempfile import TemporaryDirectory
54
1615
1716@pytest .mark .filterwarnings ("ignore:A configured store is unstable and may change in a backwards incompatible way. Use at your own risk." )
1817class TestRocksDBStore (ContextManagerStoreTestMixin , BaseStoreTests ):
19- @override
20- @pytest .fixture
21- async def store (self ) -> AsyncGenerator [RocksDBStore , None ]:
22- """Create a RocksDB store for testing."""
23- # Create a temporary directory for the RocksDB database
18+ @pytest .fixture (scope = "session" )
19+ def rocksdb_path (self ) -> Path :
2420 with TemporaryDirectory () as temp_dir :
2521 db_path = Path (temp_dir ) / "test_db"
2622 db_path .mkdir (parents = True , exist_ok = True )
27- rocksdb_store = RocksDBStore (path = db_path )
28- yield rocksdb_store
23+ return db_path
24+
25+ @override
26+ @pytest .fixture
27+ def store (self , rocksdb_path : Path ) -> RocksDBStore :
28+ """Create a RocksDB store for testing."""
29+ store = RocksDBStore (path = rocksdb_path )
30+
31+ # Wipe the store before returning it
32+ client = store ._db
33+ for key in client .keys (backwards = True ):
34+ client .delete (key = key )
35+
36+ return store
2937
3038 async def test_rocksdb_path_connection (self ):
3139 """Test RocksDB store creation with path."""
Original file line number Diff line number Diff line change 22# from the original file 'test_rocksdb.py'
33# DO NOT CHANGE! Change the original file instead.
44import json
5- from collections .abc import Generator
65from pathlib import Path
76from tempfile import TemporaryDirectory
87
1918
2019@pytest .mark .filterwarnings ("ignore:A configured store is unstable and may change in a backwards incompatible way. Use at your own risk." )
2120class TestRocksDBStore (ContextManagerStoreTestMixin , BaseStoreTests ):
22- @override
23- @pytest .fixture
24- def store (self ) -> Generator [RocksDBStore , None , None ]:
25- """Create a RocksDB store for testing."""
26- # Create a temporary directory for the RocksDB database
21+ @pytest .fixture (scope = "session" )
22+ def rocksdb_path (self ) -> Path :
2723 with TemporaryDirectory () as temp_dir :
2824 db_path = Path (temp_dir ) / "test_db"
2925 db_path .mkdir (parents = True , exist_ok = True )
30- rocksdb_store = RocksDBStore (path = db_path )
31- yield rocksdb_store
26+ return db_path
27+
28+ @override
29+ @pytest .fixture
30+ def store (self , rocksdb_path : Path ) -> RocksDBStore :
31+ """Create a RocksDB store for testing."""
32+ store = RocksDBStore (path = rocksdb_path )
33+
34+ # Wipe the store before returning it
35+ client = store ._db
36+ for key in client .keys (backwards = True ):
37+ client .delete (key = key )
38+
39+ return store
3240
3341 def test_rocksdb_path_connection (self ):
3442 """Test RocksDB store creation with path."""
You can’t perform that action at this time.
0 commit comments