From 3c692018cdc5b96a8bd7ec8cfd05ae9bebe3e24a Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:41:16 +1100 Subject: [PATCH] fix(db): make idempotency test actually test something --- tests/test_sqlite_migrator.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_sqlite_migrator.py b/tests/test_sqlite_migrator.py index 6519913fe6..bafebadcbe 100644 --- a/tests/test_sqlite_migrator.py +++ b/tests/test_sqlite_migrator.py @@ -163,9 +163,16 @@ def test_db_version_gt_last_migration(migrator: SQLiteMigrator, good_migration: assert migrator._get_current_version() == 2 -def test_idempotent_migrations(migrator: SQLiteMigrator, good_migration: Migration): +def test_idempotent_migrations(migrator: SQLiteMigrator): migrator._create_version_table() - migrator.register_migration(good_migration) + + def create_test_table(cursor: sqlite3.Cursor) -> None: + # This SQL throws if run twice + cursor.execute("CREATE TABLE test (id INTEGER PRIMARY KEY);") + + migration = Migration(db_version=1, app_version="1.0.0", migrate=create_test_table) + + migrator.register_migration(migration) migrator.run_migrations() + # not throwing is sufficient migrator.run_migrations() - assert migrator._get_current_version() == 1