Different db for testing in Django?

后端 未结 8 2028
轻奢々
轻奢々 2020-12-04 15:12
DATABASES = {
#    \'default\': {
#        \'ENGINE\': \'postgresql_psycopg2\',
#        ...
#    }

    # for unit tests
    \'default\': {
        \'ENGINE\': \'dj         


        
8条回答
  •  北海茫月
    2020-12-04 15:45

    Though this is already solved...

    If your database for tests is just a normal DB:

    I think you are not doing unit test since you rely in the database. Anyway, django contains a test type for that (not unitary): django.test.TestCase

    You need to derive from django.test.TestCase instead of unittest.TestCase that will create a fresh rehershal database for you that will be destroyed when the test end.

    There are interesting explanations/tips about testing with db in the following link
    Testing Django Applications

提交回复
热议问题