Commit 935159d9 authored by Preston Timmons's avatar Preston Timmons Committed by Tim Graham
Browse files

[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.
parent 55da4e81
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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

+19 −1
Original line number Diff line number Diff line
@@ -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 = []
+7 −0
Original line number Diff line number Diff line
import unittest


class SampleTest(unittest.TestCase):

    def test_one(self):
        pass