Skip to content

Instantly share code, notes, and snippets.

@adamchainz
Last active June 29, 2023 14:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamchainz/5b2cdac99c819e6017b7097320536b43 to your computer and use it in GitHub Desktop.
Save adamchainz/5b2cdac99c819e6017b7097320536b43 to your computer and use it in GitHub Desktop.
Django test for pending migrations
from io import StringIO
from django.core.management import call_command
from django.test import TestCase
class PendingMigrationsTests(TestCase):
def test_no_pending_migrations(self):
out = StringIO()
try:
call_command(
"makemigrations",
"--dry-run",
"--check",
stdout=out,
stderr=StringIO(),
)
except SystemExit: # pragma: no cover
raise AssertionError(
"Pending migrations:\n" + out.getvalue()
) from None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment