Disable migrations when running unit tests in Django 1.7

后端 未结 7 1198
一向
一向 2020-11-30 19:57

Django 1.7 introduced database migrations.

When running the unit tests in Django 1.7, it forces a migrate, that takes a long time. So I woul

7条回答
  •  离开以前
    2020-11-30 20:43

    Here is the end of my settings file :

    class DisableMigrations(object):
    
        def __contains__(self, item):
            return True
    
        def __getitem__(self, item):
            return None
    
    
    TESTS_IN_PROGRESS = False
    if 'test' in sys.argv[1:] or 'jenkins' in sys.argv[1:]:
        logging.disable(logging.CRITICAL)
        PASSWORD_HASHERS = (
            'django.contrib.auth.hashers.MD5PasswordHasher',
        )
        DEBUG = False
        TEMPLATE_DEBUG = False
        TESTS_IN_PROGRESS = True
        MIGRATION_MODULES = DisableMigrations()
    

    based on this snippet

    I disabled migrations only when tests are running

提交回复
热议问题