【问题标题】:Django: How to run tests against empty (non populated) databaseDjango:如何对空(未填充)数据库运行测试
【发布时间】:2018-08-27 09:28:17
【问题描述】:

通过运行“./manage.py test”,来自本地“postgres”数据库的数据被填充到“test_postgres”数据库中。我无法找到方法,如何禁用此行为。 通过运行“./manage.py test”,我想获得具有应用迁移的非填充数据库。

class Local(Common):
    DEBUG = True

    # Testing
    INSTALLED_APPS = Common.INSTALLED_APPS
    INSTALLED_APPS += ('django_nose',)
    TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
    NOSE_ARGS = [
        BASE_DIR,
        '-s',
        '--nologcapture',
        '--with-coverage',
        '--with-progressive'
    ]
    # Postgres
    DATABASES = {
        'default': dj_database_url.config(
            default='postgres://postgres:@postgres:5432/postgres',
            conn_max_age=int(os.getenv('POSTGRES_CONN_MAX_AGE', 600)),
        )
    }

【问题讨论】:

    标签: python django unit-testing django-testing django-tests


    【解决方案1】:

    通过运行“./manage.py test”,本地“postgres”数据库中的数据被填充到“test_postgres”数据库中。

    不,不是。 Django 将为每个测试创建一个新的空数据库。

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多