Skip to content

Instantly share code, notes, and snippets.

@davidszotten
Created June 3, 2016 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidszotten/56cb4583c00b7f694aa52796817e6450 to your computer and use it in GitHub Desktop.
Save davidszotten/56cb4583c00b7f694aa52796817e6450 to your computer and use it in GitHub Desktop.
from django.core.management import call_command
from django.core.management.commands.makemigrations import Command
from django.db.migrations.writer import MigrationWriter
import mock
import pytest
def test_migrations_up_to_date():
# --exit exits if there are _no_ changes, which is what we are looking for
with pytest.raises(SystemExit):
with mock.patch.object(Command, 'write_migration_files') as write:
call_command('makemigrations', dry_run=True, exit=True)
# output the actual migration contents for easier fixing
(changes,), _ = write.call_args
for app_label, app_migrations in changes.items():
print "Migrations for '%s':\n" % app_label
for migration in app_migrations:
writer = MigrationWriter(migration)
print writer.as_string()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment