Fix database URI for concurrent test workers

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
Carlo Costino
2023-08-15 09:58:54 -04:00
parent d9abca9dbe
commit 5519d17e09

View File

@@ -88,16 +88,18 @@ def create_test_db(database_uri):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def _notify_db(notify_api): def _notify_db(notify_api, worker_id):
""" """
Manages the connection to the database. Generally this shouldn't be used, instead you should use the Manages the connection to the database. Generally this shouldn't be used, instead you should use the
`notify_db_session` fixture which also cleans up any data you've got left over after your test run. `notify_db_session` fixture which also cleans up any data you've got left over after your test run.
""" """
# Create a database for this worker thread; note that the # Create a database for this worker thread; note that we still have
# SQLALCHEMY_DATABASE_URI config variable was already reset with the # to reset it here to point to the correct database.
# worker ID in the notify_app fixture method.
from flask import current_app from flask import current_app
current_app.config['SQLALCHEMY_DATABASE_URI'] += '_{}'.format(
worker_id
)
create_test_db(current_app.config['SQLALCHEMY_DATABASE_URI']) create_test_db(current_app.config['SQLALCHEMY_DATABASE_URI'])
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))