Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed #10165 -- Use settings.TEST_RUNNER in runtests.py
This permits running Django's core tests under an alternative test runner. Most
likely useful to non-CPython implementations, rather than much else (since
Django's core tests might assume things about the test runner).

Patch from Leo Soto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Feb 28, 2009
1 parent 415ffa8 commit beb2005
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
11 changes: 2 additions & 9 deletions django/core/management/commands/test.py
Expand Up @@ -14,18 +14,11 @@ class Command(BaseCommand):

def handle(self, *test_labels, **options):
from django.conf import settings
from django.test.utils import get_runner

verbosity = int(options.get('verbosity', 1))
interactive = options.get('interactive', True)

test_path = settings.TEST_RUNNER.split('.')
# Allow for Python 2.5 relative paths
if len(test_path) > 1:
test_module_name = '.'.join(test_path[:-1])
else:
test_module_name = '.'
test_module = __import__(test_module_name, {}, {}, test_path[-1])
test_runner = getattr(test_module, test_path[-1])
test_runner = get_runner(settings)

failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
if failures:
Expand Down
11 changes: 11 additions & 0 deletions django/test/utils.py
Expand Up @@ -65,3 +65,14 @@ def teardown_test_environment():

del mail.outbox


def get_runner(settings):
test_path = settings.TEST_RUNNER.split('.')
# Allow for Python 2.5 relative paths
if len(test_path) > 1:
test_module_name = '.'.join(test_path[:-1])
else:
test_module_name = '.'
test_module = __import__(test_module_name, {}, {}, test_path[-1])
test_runner = getattr(test_module, test_path[-1])
return test_runner
8 changes: 6 additions & 2 deletions tests/runtests.py
Expand Up @@ -149,8 +149,12 @@ def django_tests(verbosity, interactive, test_labels):
pass

# Run the test suite, including the extra validation tests.
from django.test.simple import run_tests
failures = run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
from django.test.utils import get_runner
if not hasattr(settings, 'TEST_RUNNER'):
settings.TEST_RUNNER = 'django.test.simple.run_tests'
test_runner = get_runner(settings)

failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
if failures:
sys.exit(failures)

Expand Down

0 comments on commit beb2005

Please sign in to comment.