Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to test django project

Tags:

python

django

I wrote some test case to test my django project, when I run them in jenkins it always create a default database, I want to test my project with my own database, how to do?

like image 938
bright Avatar asked Nov 04 '22 12:11

bright


1 Answers

Django always expects to have a default database as described in the documentation for the DATABASES setting.

The default tags is simply the name by which you refer to the database, not the name of the database itself. In the documentation example above, even though the database handle is default, the name of the database itself is mydatabase.

When you're testing, it is usual to use a different database than your production database and for this you can use the TEST_NAME specification for the database. The following settings.py shows the names of the databases used during production and unit testing.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase',
        'TEST_NAME': 'mytestdatabase'
    }
}

The following link gives some useful information on testing. https://docs.djangoproject.com/en/dev/topics/testing/

like image 133
Austin Phillips Avatar answered Nov 15 '22 05:11

Austin Phillips