ValueError: No module named 'notmigrations' during unit tests
Asked Answered
B

1

5

I have django application 2.1.7 with django-tenant plugin (creating schemas in the database for saas).

My problem is unit testing. I run the command: python manage.py test --settings=project.settings_test and I'm getting a error: ImportError: No module named 'notmigrations'

My code in settings_test file

from .settings_base import *


class DisableMigrations(object):
    def __contains__(self, item):
        return True

    def __getitem__(self, item):
        return 'notmigrations'

MIGRATION_MODULES = DisableMigrations()
Battaglia answered 28/4, 2019 at 21:42 Comment(0)
E
6

You are using an ancient hack intended for really old versions of Django (< 1.9), from before there was support to disable migrations in testing. Since you're now using a relatively recent version of Django (2.1.7), delete that code from your test settings module.

Should you want to disable migrations in tests, use the modern approach, which is putting the value to None in MIGRATION_MODULES setting.

When you supply None as a value for an app, Django will consider the app as an app without migrations regardless of an existing migrations submodule. This can be used, for example, in a test settings file to skip migrations while testing (tables will still be created for the apps’ models).

# test_settings.py
from settings import *

MIGRATION_MODULES = {
    'auth': None,
    'contenttypes': None,
    'sessions': None,
    ...
    'myapp1': None,
    'myapp2': None,
}
Expiration answered 28/4, 2019 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.