From 5519d17e09747e098c0111e086e8b4d0b8a0054b Mon Sep 17 00:00:00 2001 From: Carlo Costino Date: Tue, 15 Aug 2023 09:58:54 -0400 Subject: [PATCH] Fix database URI for concurrent test workers Signed-off-by: Carlo Costino --- tests/conftest.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 88b849987..e2ffb0bd2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -88,16 +88,18 @@ def create_test_db(database_uri): @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 `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 - # SQLALCHEMY_DATABASE_URI config variable was already reset with the - # worker ID in the notify_app fixture method. + # Create a database for this worker thread; note that we still have + # to reset it here to point to the correct database. from flask import current_app + current_app.config['SQLALCHEMY_DATABASE_URI'] += '_{}'.format( + worker_id + ) create_test_db(current_app.config['SQLALCHEMY_DATABASE_URI']) BASE_DIR = os.path.dirname(os.path.dirname(__file__))