Skip to content

Commit

Permalink
Update tests for missing migrations
Browse files Browse the repository at this point in the history
The test passed originally ran with the suite, and managed to fail
independently. This updates the test itself to make use of Django's new
migration option `--check` and to add a separate step to the build
command.

gh-145
  • Loading branch information
bennylope committed Jan 11, 2018
1 parent 3aeb59f commit 9892d6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -64,6 +64,7 @@ test-all:
check: clean-build clean-pyc clean-test lint test-coverage

build: clean ## Create distribution files for release
pytest -k test_no_missing_migrations
python setup.py sdist bdist_wheel

release: build ## Create distribution files and publish to PyPI
Expand Down
21 changes: 2 additions & 19 deletions tests/test_migrations.py
Expand Up @@ -2,30 +2,13 @@
Tests that migrations are not missing
"""

try:
from io import StringIO
except ImportError:
from StringIO import StringIO

import pytest

from django.core.management import call_command
from django.conf import settings


@pytest.mark.django_db
def test_no_missing_migrations():
"""Check no model changes have been made since the last `./manage.py makemigrations`.
Pulled from mozilla/treeherder #dd53914, subject to MPL
"""
try:
with pytest.raises(SystemExit) as e:
# Replace with `check_changes=True` once we're using a Django version that includes:
# https://code.djangoproject.com/ticket/25604
# https://github.com/django/django/pull/5453
call_command('makemigrations', interactive=False, dry_run=True, exit_code=True)
assert str(e.value) == '1'
except TypeError:
out = StringIO()
call_command('makemigrations', interactive=False, dry_run=True, check=True, stdout=out)
assert str(out.getvalue()) == 'No changes detected\n'
call_command('makemigrations', check=True, dry_run=True)

0 comments on commit 9892d6f

Please sign in to comment.