Skip to content

Commit

Permalink
making changes suggested by @jezdez
Browse files Browse the repository at this point in the history
  • Loading branch information
myusuf3 committed Sep 8, 2012
1 parent 4d0961d commit 84bc4b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions django/conf/global_settings.py
Expand Up @@ -589,13 +589,13 @@
TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'

# The root directory to discover tests within
TEST_DISCOVERY_ROOT = '.'
TEST_DISCOVER_ROOT = '.'

# The pattern used for discovering tests
TEST_DISCOVERY_PATTERN = 'test*.py'
TEST_DISCOVER_PATTERN = 'test*.py'

# The top level directory to discover tests within
TEST_DISCOVERY_TOP_LEVEL = None
TEST_DISCOVER_TOP_LEVEL = None

############
# FIXTURES #
Expand Down
2 changes: 1 addition & 1 deletion django/conf/project_template/project_name/settings.py
Expand Up @@ -124,7 +124,7 @@


# Test runner to be used for testing
TEST_RUNNER = 'django.test.runner.DiscoveryRunner'
TEST_RUNNER = 'django.test.runner.DiscoverRunner'


# A sample logging configuration. The only tangible logging
Expand Down
19 changes: 14 additions & 5 deletions django/test/runner.py
@@ -1,19 +1,28 @@
import os

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.simple import DjangoTestSuiteRunner, reorder_suite
from django.utils.importlib import import_module
from django.utils.unittest.loader import defaultTestLoader

try:
from django.utils.unittest.loader import defaultTestLoader
except ImportError:
try:
from unittest2 import defaultTestLoader
except ImportError:
raise ImproperlyConfigured("Couldn't import unittest2 default "
"test loader, install the unittest2 library.")

class DiscoveryRunner(DjangoTestSuiteRunner):

class DiscoverRunner(DjangoTestSuiteRunner):
"""A test suite runner that uses unittest2 test discovery."""
def build_suite(self, test_labels, extra_tests=None, **kwargs):
suite = None
root = settings.TEST_DISCOVERY_ROOT
pattern = settings.TEST_DISCOVERY_PATTERN
top_level = settings.TEST_DISCOVERY_TOP_LEVEL
root = settings.TEST_DISCOVER_ROOT
pattern = settings.TEST_DISCOVER_PATTERN
top_level = settings.TEST_DISCOVER_TOP_LEVEL

if test_labels:
suite = defaultTestLoader.loadTestsFromNames(test_labels)
Expand Down
18 changes: 9 additions & 9 deletions tests/regressiontests/test_runner/tests.py
Expand Up @@ -10,7 +10,7 @@
from django import db
from django.test import simple, TransactionTestCase, skipUnlessDBFeature
from django.test.simple import DjangoTestSuiteRunner, get_tests
from django.test.runner import DiscoveryRunner
from django.test.runner import DiscoverRunner
from django.test.testcases import connections_support_transactions
from django.utils import unittest
from django.utils.importlib import import_module
Expand All @@ -22,8 +22,8 @@

TEST_APP_OK = 'regressiontests.test_runner.valid_app.models'
TEST_APP_ERROR = 'regressiontests.test_runner.invalid_app.models'
DISCOVERY_APP_TESTS = 'regressiontests.test_runner.discovery_app'
DISCOVERY_APP_MODEL_TESTS = 'regressiontests.test_runner.discovery_app.models'
DISCOVER_APP_TESTS = 'regressiontests.test_runner.discovery_app'
DISCOVER_APP_MODEL_TESTS = 'regressiontests.test_runner.discovery_app.models'


class DependencyOrderingTests(unittest.TestCase):
Expand Down Expand Up @@ -285,20 +285,20 @@ def test_autoincrement_reset2(self):
self.assertEqual(p.pk, 1)


class DiscoveryTestRunnerTests(AdminScriptTestCase):
class DiscoverTestRunnerTests(AdminScriptTestCase):

def test_discovery_of_tests_default_settings(self):
suite = DiscoveryRunner().build_suite((DISCOVERY_APP_TESTS, ))
suite = DiscoverRunner().build_suite((DISCOVER_APP_TESTS, ))
discovered_tests = suite.countTestCases()
self.assertEqual(3, discovered_tests)

def test_discovery_of_tests_inside_module(self):
suite = DiscoveryRunner().build_suite((DISCOVERY_APP_MODEL_TESTS, ))
suite = DiscoverRunner().build_suite((DISCOVER_APP_MODEL_TESTS, ))
discovered_tests = suite.countTestCases()
self.assertEqual(1, discovered_tests)

@override_settings(TEST_DISCOVERY_PATTERN = '*_test.py')
@override_settings(TEST_DISCOVER_PATTERN='*_test.py')
def test_discovery_of_tests_with_pattern(self):
suite = DiscoveryRunner().build_suite((DISCOVERY_APP_TESTS, ))
suite = DiscoverRunner().build_suite((DISCOVER_APP_TESTS, ))
discovered_tests = suite.countTestCases()
self.assertEqual(4, discovered_tests)
self.assertEqual(4, discovered_tests)

0 comments on commit 84bc4b6

Please sign in to comment.