Created
February 10, 2017 20:39
-
-
Save smcoll/8a3579feff6ab2c024f67da5f6a56280 to your computer and use it in GitHub Desktop.
Django test to detect uncreated/unmerged migration files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from StringIO import StringIO | |
from django.core.management import call_command | |
from django.test import TestCase, override_settings | |
class TestMigrationDiscrepancies(TestCase): | |
@override_settings(MIGRATION_MODULES={}) | |
def test_for_missing_migrations(self): | |
output = StringIO() | |
try: | |
call_command('makemigrations', interactive=False, dry_run=True, exit_code=True, stdout=output) | |
except SystemExit as e: | |
# The exit code will be 1 when there are no missing migrations | |
assert unicode(e) == '1' | |
else: | |
self.fail("There are missing migrations:\n %s" % output.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Django 2.0: