From bffeaa773a8c3eccb4ec65967044c66df5f6693e Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 22 Jun 2016 15:11:47 +0100 Subject: [PATCH] Remove db.drop_all from notify_db session fixture to speed up tests We were dropping all tables at the end of the test run, however the alembic_version table is not part of the metadata so was being persisted. Alembic then doesn't upgrade the database next test run, since the version appears up to date, so we were, in the notify_db_session fixture, recreating from MetaData (sqlalchemy models). This involves quite a costly comparison of the postgres system tables and the tables in models.py, which was adding half a second to each test that uses the notify_db_session fixture (virtually all of them). --- tests/conftest.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 26af719b0..2499360dd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,7 +39,6 @@ def notify_db(notify_api, request): def teardown(): db.session.remove() - db.drop_all() db.get_engine(notify_api).dispose() request.addfinalizer(teardown) @@ -47,15 +46,14 @@ def notify_db(notify_api, request): @pytest.fixture(scope='function') -def notify_db_session(request): +def notify_db_session(request, notify_db): def teardown(): - db.session.remove() - for tbl in reversed(meta.sorted_tables): + notify_db.session.remove() + for tbl in reversed(notify_db.metadata.sorted_tables): if tbl.name not in ["provider_details"]: - db.engine.execute(tbl.delete()) - db.session.commit() + notify_db.engine.execute(tbl.delete()) + notify_db.session.commit() - meta = MetaData(bind=db.engine, reflect=True) request.addfinalizer(teardown)