Skip to content

Commit 58a72f4

Browse files
committed
Avoid running migration check multiple times in tests
1 parent ed23011 commit 58a72f4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test_app/tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ def openapi_schema():
3838
return generator.get_schema(request=drf_request)
3939

4040

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

59+
if (not hasattr(app_config, 'module')) or (not hasattr(app_config.module, 'migrations')):
60+
continue # might catch a stub app
61+
5762
migration_module = app_config.module.migrations
5863
for step in dir(migration_module):
5964
if not re.match(r'\d{4}_', step):

0 commit comments

Comments
 (0)