[1.7.x] Fixed #22478 -- Regression in test label discovery.

As part of the app-loading updates the old test runner was changed to not
require a models module. This introduced a regression in behavior so
applabel.TestCase failed for tests defined in a directory.

The fix is thanks to yakky and rtnpro.
This commit is contained in:
Preston Timmons 2014-04-21 14:46:09 -05:00 committed by Tim Graham
parent 55da4e818d
commit 935159d951
3 changed files with 27 additions and 2 deletions

View File

@ -181,7 +181,7 @@ def build_test(label):
TestClass = None TestClass = None
for module in test_modules: for module in test_modules:
TestClass = getattr(models_module, parts[1], None) TestClass = getattr(module, parts[1], None)
if TestClass is not None: if TestClass is not None:
break break

View File

@ -12,7 +12,11 @@ from django.core.management import call_command
from django import db from django import db
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.testcases import connections_support_transactions from django.test.testcases import connections_support_transactions
from django.test.utils import IgnoreAllDeprecationWarningsMixin, override_system_checks from django.test.utils import (
IgnoreAllDeprecationWarningsMixin,
override_settings,
override_system_checks
)
from django.utils import six from django.utils import six
from admin_scripts.tests import AdminScriptTestCase from admin_scripts.tests import AdminScriptTestCase
@ -242,6 +246,20 @@ class ModulesTestsPackages(IgnoreAllDeprecationWarningsMixin, unittest.TestCase)
get_tests(app_config) get_tests(app_config)
class LabelDiscoveryTest(TestCase):
@override_settings(INSTALLED_APPS=['test_runner.valid_app'])
def test_discover_within_package(self):
"""
Verify labels like applabel.TestCase find tests defined in
applabel/tests/__init__.py. Fixes #22478.
"""
from django.test.simple import build_test
suite = build_test('valid_app.SampleTest')
self.assertEqual(suite.countTestCases(), 1)
class Sqlite3InMemoryTestDbs(TestCase): class Sqlite3InMemoryTestDbs(TestCase):
available_apps = [] available_apps = []

View File

@ -0,0 +1,7 @@
import unittest
class SampleTest(unittest.TestCase):
def test_one(self):
pass