Skip to content

Commit

Permalink
Avoid running migration check multiple times in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Dec 6, 2024
1 parent ed23011 commit 58a72f4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test_app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ def openapi_schema():
return generator.get_schema(request=drf_request)


def test_migrations_okay(*args, **kwargs):
def test_migrations_okay(apps, app_config, **kwargs):
"""This test is not about the code, but for verifying your own state.
If you are not migrated to the correct state, this may hopefully alert you.
This is targeted toward situations like switching branches.
"""
if app_config.label != 'test_app':
return # so that it is only ran once
disk_steps = defaultdict(set)
app_exceptions = {'default': 'auth', 'social_auth': 'social_django'}
for app in MigrationRecorder.Migration.objects.values_list('app', flat=True).distinct():
Expand All @@ -54,6 +56,9 @@ def test_migrations_okay(*args, **kwargs):
except LookupError:
raise RuntimeError(f'App {app} is present in the recorded migrations but not installed, perhaps you need --create-db?')

if (not hasattr(app_config, 'module')) or (not hasattr(app_config.module, 'migrations')):
continue # might catch a stub app

migration_module = app_config.module.migrations
for step in dir(migration_module):
if not re.match(r'\d{4}_', step):
Expand Down

0 comments on commit 58a72f4

Please sign in to comment.