From 126761db5165fe9a5d7241ba14af91bbadc9d6e6 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 9 Nov 2015 12:04:50 +0000 Subject: [PATCH] Added --postgres argument to runtests.py Makes running the tests against PostgreSQL a bit easier --- docs/contributing/developing.rst | 20 +++++++++++++------- runtests.py | 12 +++++++++--- 2 files changed, 22 insertions(+), 10 deletions(-) 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)