|Version 4 (modified by Simon G. <dev@…>, 8 years ago) (diff)|
Testing the django framework
(as opposed to testing your app).
If your app is having trouble, it is a good idea to run django's tests to make sure django is functioning properly. it also helps the developers catch bugs that could be system dependent, like OS, python version, db, etc.
To run the tests, you need to supply a very small settings file. you will probably want to write a small script to run tests and log the results. below is what I use.
# settings_sqlite.py DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = 'demodb' ROOT_URLCONF=None SITE_ID=1
# settings_mysql.py DATABASE_ENGINE = 'mysql' DATABASE_USER = 'foo' DATABASE_PASSWORD = 'abc' DATABASE_HOST = '' DATABASE_PORT = '' ROOT_URLCONF=None SITE_ID=1 TEST_DATABASE_CHARSET = 'utf8'
# settings_memory.py # this should be faster than the others because it uses an in-memory SQLite DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = ':memory:' DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = '' LANGUAGE_CODE = 'en-us' SITE_ID = 1 ROOT_URLCONF = ''
# runtests.sh # runs the django tests, logs the output set -x echo svnversion $(svnversion) > runtests.log cat settings_sqlite.py>> runtests.log ./runtests.py --settings settings_sqlite 2>&1|tee --append runtests.log cat settings_mysql.py>> runtests.log ./runtests.py --settings settings_mysql 2>&1|tee --append runtests.log
rem runtests.bat runtests.py --settings settings_sqlite 2>&1
Note: most of the runtests.py output is to stderr. the 2>&1 redirects that to stdout so that it can be redirected into a file, which is handy for posting when tests fail.
See also #4223
If you write tests place them as follows:
- if the test tests a core feature of models, it should live in modeltests;
- if it tests a contrib app, it should live as a test module in the contrib app itself;
- otherwise it should go in regressiontests