Skip to content

Commit

Permalink
fix(tests): use PyTests's tmp_path to create temp directories
Browse files Browse the repository at this point in the history
  • Loading branch information
msiemens committed Nov 26, 2022
1 parent cd0b719 commit 50c3a1d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path
import tempfile
from pathlib import Path

import pytest # type: ignore

Expand All @@ -9,17 +10,16 @@


@pytest.fixture(params=['memory', 'json'])
def db(request):
with tempfile.TemporaryDirectory() as tmpdir:
if request.param == 'json':
db_ = TinyDB(os.path.join(tmpdir, 'test.db'), storage=JSONStorage)
else:
db_ = TinyDB(storage=MemoryStorage)
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')
db_.drop_tables()
db_.insert_multiple({'int': 1, 'char': c} for c in 'abc')

yield db_
yield db_


@pytest.fixture
Expand Down

0 comments on commit 50c3a1d

Please sign in to comment.