From c6a578ee2d1df5d9886e146ba30842bd42b4328f Mon Sep 17 00:00:00 2001 From: John Hensley Date: Tue, 11 May 2021 10:19:57 -0400 Subject: [PATCH] In test_alembic.py, test upgrade/downgrade more efficiently Walking the change path ourselves and calling alembic for each revision is slow, and doesn't match how migrations are applied in production. Simply calling alembic once with the target revision is more accurate and much faster since it doesn't incur the overhead of the extra invocations. Also, since test_alembic_migration_downgrade upgrades to the target migration before downgrading to base, test_alembic_migration_upgrade is superfluous. I've renamed test_alembic_migration_downgrade to reflect what it does. --- securedrop/tests/test_alembic.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/securedrop/tests/test_alembic.py b/securedrop/tests/test_alembic.py index 1dab93c89e..9502f08213 100644 --- a/securedrop/tests/test_alembic.py +++ b/securedrop/tests/test_alembic.py @@ -121,23 +121,9 @@ def test_alembic_head_matches_db_models(journalist_app, @pytest.mark.parametrize('migration', ALL_MIGRATIONS) -def test_alembic_migration_upgrade(alembic_config, config, migration): - # run migrations in sequence from base -> head - for mig in list_migrations(alembic_config, migration): - upgrade(alembic_config, mig) - - -@pytest.mark.parametrize('migration', ALL_MIGRATIONS) -def test_alembic_migration_downgrade(alembic_config, config, migration): - # upgrade to the parameterized test case ("head") +def test_alembic_migration_up_and_down(alembic_config, config, migration): upgrade(alembic_config, migration) - - # run migrations in sequence from "head" -> base - migrations = list_migrations(alembic_config, migration) - migrations.reverse() - - for mig in migrations: - downgrade(alembic_config, mig) + downgrade(alembic_config, "base") @pytest.mark.parametrize('migration', ALL_MIGRATIONS)