diff --git a/docs/contributing/developing.rst b/docs/contributing/developing.rst index a2e41d4d1a..3ac0a68349 100644 --- a/docs/contributing/developing.rst +++ b/docs/contributing/developing.rst @@ -71,17 +71,23 @@ an argument to ``runtests.py``:: **Testing against PostgreSQL** -By default, Wagtail tests against SQLite. If you need to test against a -different database, set the ``DATABASE_ENGINE`` environment variable to the -name of the Django database backend to test against:: +By default, Wagtail tests against SQLite. You can switch to using PostgreSQL by +using the ``--postgres`` argument:: - DATABASE_ENGINE=django.db.backends.postgresql_psycopg2 python runtests.py - -This will create a new database called ``test_wagtail`` in PostgreSQL and run -the tests against it. + python runtests.py --postgres If you need to use a different user, password or host. Use the ``PGUSER``, ``PGPASSWORD`` and ``PGHOST`` environment variables. +**Testing against a different database** + +If you need to test against a different database, set the ``DATABASE_ENGINE`` +environment variable to the name of the Django database backend to test against:: + + DATABASE_ENGINE=django.db.backends.mysql python runtests.py + +This will create a new database called ``test_wagtail`` in MySQL and run +the tests against it. + **Testing Elasticsearch** To test Elasticsearch, you need to have the ``elasticsearch`` package installed. diff --git a/runtests.py b/runtests.py index a1925f907d..1a674c29a1 100755 --- a/runtests.py +++ b/runtests.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + import sys import os import shutil @@ -6,8 +7,6 @@ import warnings from django.core.management import execute_from_command_line -from wagtail.tests.settings import STATIC_ROOT, MEDIA_ROOT - os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail.tests.settings' @@ -17,10 +16,17 @@ def runtests(): warnings.simplefilter('default', DeprecationWarning) warnings.simplefilter('default', PendingDeprecationWarning) - argv = sys.argv[:1] + ['test'] + sys.argv[1:] + args = sys.argv[1:] + + if '--postgres' in args: + os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2' + args.remove('--postgres') + + argv = sys.argv[:1] + ['test'] + args try: execute_from_command_line(argv) finally: + from wagtail.tests.settings import STATIC_ROOT, MEDIA_ROOT shutil.rmtree(STATIC_ROOT, ignore_errors=True) shutil.rmtree(MEDIA_ROOT, ignore_errors=True)