Skip to content

Commit

Permalink
Fix an incompatibility with Django 1.2 and XML reports.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
David Thompson authored and garethr committed Jun 19, 2010
1 parent 8d6176a commit 5f9ca83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/test_extensions/management/commands/test.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions src/test_extensions/testrunners/xmloutput.py
Expand Up @@ -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()

Expand Down

0 comments on commit 5f9ca83

Please sign in to comment.