Skip to content

Commit

Permalink
In test_alembic.py, test upgrade/downgrade more efficiently
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmol committed May 11, 2021
1 parent 67f77a3 commit c6a578e
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions securedrop/tests/test_alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c6a578e

Please sign in to comment.