From 5422386de4455960234289ff1c9be6a7321d2b1c Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 24 Sep 2018 11:10:26 -0400 Subject: [PATCH] Make absolutely sure we have foreign keys enabled on all tests --- test/fixtures.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/fixtures.py b/test/fixtures.py index 3822d28f3..e442234b8 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -135,6 +135,7 @@ def appconfig(database_uri): @pytest.fixture() def initialized_db(appconfig): """ Configures the database for the database found in the appconfig. """ + under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI')) # Configure the database. configure(appconfig) @@ -144,8 +145,12 @@ def initialized_db(appconfig): model._basequery.get_public_repo_visibility() model.log.get_log_entry_kinds() + if not under_test_real_database: + # Make absolutely sure foreign key constraints are on. + db.obj.execute_sql('PRAGMA foreign_keys = ON;') + assert db.obj.execute_sql('PRAGMA foreign_keys;').fetchone()[0] == 1 + # If under a test *real* database, setup a savepoint. - under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI')) if under_test_real_database: with db.transaction(): test_savepoint = db.savepoint()