Skip to content

Commit 348aabe

Browse files
committed
Updates for rocksdb tests
1 parent 6686ba2 commit 348aabe

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

key-value/key-value-aio/tests/stores/rocksdb/test_rocksdb.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from collections.abc import AsyncGenerator
32
from pathlib import Path
43
from tempfile import TemporaryDirectory
54

@@ -16,16 +15,25 @@
1615

1716
@pytest.mark.filterwarnings("ignore:A configured store is unstable and may change in a backwards incompatible way. Use at your own risk.")
1817
class 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."""

key-value/key-value-sync/tests/code_gen/stores/rocksdb/test_rocksdb.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# from the original file 'test_rocksdb.py'
33
# DO NOT CHANGE! Change the original file instead.
44
import json
5-
from collections.abc import Generator
65
from pathlib import Path
76
from tempfile import TemporaryDirectory
87

@@ -19,16 +18,25 @@
1918

2019
@pytest.mark.filterwarnings("ignore:A configured store is unstable and may change in a backwards incompatible way. Use at your own risk.")
2120
class 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."""

0 commit comments

Comments
 (0)