Make the default db for all tests, remove after each test

pull/24/head^2
Michael Egorov 2017-09-05 16:39:13 -07:00
parent a6be3fb1d9
commit dcfec2d7ab
2 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,16 @@
import nkms.db
import shutil
import os
import appdirs
def pytest_runtest_setup(item):
# Monkey-patching for tests so that we don't overwrite the default db
nkms.db.DB_NAME = 'debug-rekeys-db'
def pytest_runtest_teardown(item, nextitem):
path = os.path.join(
appdirs.user_data_dir(nkms.db.CONFIG_APPNAME), nkms.db.DB_NAME)
if os.path.exists(path):
shutil.rmtree(path)

View File

@ -1,5 +1,4 @@
from nkms.db import DB
import shutil
import pytest
@ -19,7 +18,6 @@ def test_db():
with pytest.raises(KeyError):
db[b'x']
assert b'x' not in db
db.close()
assert db.path == db2.path
shutil.rmtree(db.path)