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).
This commit is contained in:
Leo Hemsted
2016-06-22 15:11:47 +01:00
parent 1659b64f9e
commit bffeaa773a

View File

@@ -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)