From a601a4b42d64b0a4cff0761b0b290c4fe8de7c43 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Mar 02 2017 19:24:51 +0000 Subject: use in-memory database for unit tests The main motivation here is just to avoid the tmpdir_factory fixture, which was introduced in Pytest 2.8. EPEL7 has Pytest 2.7 so this fixture is not available. But we don't really need to use a temp file at all, we can just use a SQLite in-memory database instead. --- diff --git a/tests/conftest.py b/tests/conftest.py index db596eb..f22085a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,10 +16,8 @@ import pytest from waiverdb.app import create_app, init_db @pytest.fixture(scope='session') -def app(tmpdir_factory, request): +def app(request): app = create_app('waiverdb.config.TestingConfig') - db_file = tmpdir_factory.mktemp('waiverdb').join('db.sqlite') - app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % db_file # Establish an application context before running the tests. ctx = app.app_context() ctx.push() @@ -31,12 +29,9 @@ def app(tmpdir_factory, request): return app @pytest.fixture(scope='session') -def db(app, request): +def db(app): """Session-wide test database.""" db = init_db(app) - def teardown(): - db.drop_all() - request.addfinalizer(teardown) return db @pytest.fixture(scope='function')