Skip to content

Commit 1d16385

Browse files
committed
Avoid running migration check multiple times in tests
1 parent 7602329 commit 1d16385

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
@@ -44,12 +44,14 @@ def openapi_schema():
4444
return generator.get_schema(request=drf_request)
4545

4646

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

65+
if (not hasattr(app_config, 'module')) or (not hasattr(app_config.module, 'migrations')):
66+
continue # might catch a stub app
67+
6368
migration_module = app_config.module.migrations
6469
for step in dir(migration_module):
6570
if not re.match(r'\d{4}_', step):

0 commit comments

Comments
 (0)