diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2014-04-21 14:46:09 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-04-22 12:48:39 -0400 |
| commit | 935159d9517ca951cbd5665c521d3c91102948d8 (patch) | |
| tree | 8b3b537b7ec4cf2ca5da7ca7c6348999a544e058 | |
| parent | 55da4e818d835205f42280ca06ef2a9a6d75fe08 (diff) | |
[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.
| -rw-r--r-- | django/test/simple.py | 2 | ||||
| -rw-r--r-- | tests/test_runner/tests.py | 20 | ||||
| -rw-r--r-- | tests/test_runner/valid_app/tests/__init__.py | 7 |
3 files changed, 27 insertions, 2 deletions
diff --git a/django/test/simple.py b/django/test/simple.py index 956294db82..9eafaefe7c 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -181,7 +181,7 @@ def build_test(label): TestClass = None for module in test_modules: - TestClass = getattr(models_module, parts[1], None) + TestClass = getattr(module, parts[1], None) if TestClass is not None: break diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 20e7f6b892..99907be12e 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -12,7 +12,11 @@ from django.core.management import call_command from django import db from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature 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 admin_scripts.tests import AdminScriptTestCase @@ -242,6 +246,20 @@ class ModulesTestsPackages(IgnoreAllDeprecationWarningsMixin, unittest.TestCase) 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): available_apps = [] diff --git a/tests/test_runner/valid_app/tests/__init__.py b/tests/test_runner/valid_app/tests/__init__.py index e69de29bb2..69e1edd3a3 100644 --- a/tests/test_runner/valid_app/tests/__init__.py +++ b/tests/test_runner/valid_app/tests/__init__.py @@ -0,0 +1,7 @@ +import unittest + + +class SampleTest(unittest.TestCase): + + def test_one(self): + pass |
