1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
import os.path
import tempfile
from pathlib import Path
import pytest # type: ignore
from tinydb.middlewares import CachingMiddleware
from tinydb.storages import MemoryStorage
from tinydb import TinyDB, JSONStorage
@pytest.fixture(params=['memory', 'json'])
def db(request, tmp_path: Path):
if request.param == 'json':
db_ = TinyDB(tmp_path / 'test.db', storage=JSONStorage)
else:
db_ = TinyDB(storage=MemoryStorage)
db_.drop_tables()
db_.insert_multiple({'int': 1, 'char': c} for c in 'abc')
yield db_
@pytest.fixture
def storage():
return CachingMiddleware(MemoryStorage)()
|