From 5f9ca83f98554abc2852a7823b23db9a5409f691 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 3 Jun 2010 17:12:41 +0800 Subject: [PATCH] Fix an incompatibility with Django 1.2 and XML reports. The XML test runner was previously doing a bunch of extra work instantiating a test database in a manner tied very closely to the single-database model from Django <1.2. Django 1.2 and above provides a test runner class which can simply be subclassed. There's some slightly hacky code to switch between the two. --- src/test_extensions/management/commands/test.py | 11 ++++++++++- src/test_extensions/testrunners/xmloutput.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test_extensions/management/commands/test.py b/src/test_extensions/management/commands/test.py index 31dacc1..9421e18 100755 --- a/src/test_extensions/management/commands/test.py +++ b/src/test_extensions/management/commands/test.py @@ -6,6 +6,15 @@ from django.db.models import get_app, get_apps from django.core.management.base import BaseCommand +# Django versions prior to 1.2 don't include the DjangoTestSuiteRunner class; +# Django versions since 1.2 include multi-database support, which doesn't play +# nicely with the database setup in the XML test runner. +try: + from django.test.simple import DjangoTestSuiteRunner + xml_runner = 'test_extensions.testrunners.xmloutput.XMLTestSuiteRunner' +except ImportError: # We are in a version prior to 1.2 + xml_runner = 'test_extensions.testrunners.xmloutput.run_tests' + skippers = [] class Command(BaseCommand): @@ -77,7 +86,7 @@ def handle(self, *test_labels, **options): elif options.get('figleaf'): test_runner_name = 'test_extensions.testrunners.figleafcoverage.run_tests' elif options.get('xml'): - test_runner_name = 'test_extensions.testrunners.xmloutput.run_tests' + test_runner_name = xml_runner else: test_runner_name = settings.TEST_RUNNER diff --git a/src/test_extensions/testrunners/xmloutput.py b/src/test_extensions/testrunners/xmloutput.py index 5c8aca3..318a4e2 100755 --- a/src/test_extensions/testrunners/xmloutput.py +++ b/src/test_extensions/testrunners/xmloutput.py @@ -6,6 +6,16 @@ from django.test.simple import * from django.utils.html import escape + +try: + class XMLTestSuiteRunner(DjangoTestSuiteRunner): + + def run_suite(self, suite, **kwargs): + return XMLTestRunner(verbosity=self.verbosity).run(suite) + +except NameError: # DjangoTestSuiteRunner is not available in Django < 1.2 + pass + def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): setup_test_environment()