From 99364f8a58307ef3d9427befd1f4aeb0e24ed783 Mon Sep 17 00:00:00 2001
From: Iacopo Spalletti <i.spalletti@nephila.it>
Date: Mon, 21 Apr 2014 10:18:49 +0200
Subject: [PATCH] Fixed #22478. Use correct module variable in build_tests for
cycle.
---
django/test/simple.py | 2 +-
tests/test_suite_override/sample_app/__init__.py | 1 +
tests/test_suite_override/sample_app/models.py | 6 ++++++
tests/test_suite_override/sample_app/tests/__init__.py | 2 ++
.../test_suite_override/sample_app/tests/test_module.py | 11 +++++++++++
tests/test_suite_override/tests.py | 16 +++++++++++++++-
6 files changed, 36 insertions(+), 2 deletions(-)
create mode 100644 tests/test_suite_override/sample_app/__init__.py
create mode 100644 tests/test_suite_override/sample_app/models.py
create mode 100644 tests/test_suite_override/sample_app/tests/__init__.py
create mode 100644 tests/test_suite_override/sample_app/tests/test_module.py
diff --git a/django/test/simple.py b/django/test/simple.py
index 956294d..9eafaef 100644
a
|
b
|
def build_test(label):
|
181 | 181 | |
182 | 182 | TestClass = None |
183 | 183 | for module in test_modules: |
184 | | TestClass = getattr(models_module, parts[1], None) |
| 184 | TestClass = getattr(module, parts[1], None) |
185 | 185 | if TestClass is not None: |
186 | 186 | break |
187 | 187 | |
diff --git a/tests/test_suite_override/sample_app/__init__.py b/tests/test_suite_override/sample_app/__init__.py
new file mode 100644
index 0000000..40a96af
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
diff --git a/tests/test_suite_override/sample_app/models.py b/tests/test_suite_override/sample_app/models.py
new file mode 100644
index 0000000..59875f6
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | from django.db import models |
| 3 | |
| 4 | |
| 5 | class MyModel(models.Model): |
| 6 | title = models.CharField(max_length=200) |
diff --git a/tests/test_suite_override/sample_app/tests/__init__.py b/tests/test_suite_override/sample_app/tests/__init__.py
new file mode 100644
index 0000000..5df598c
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | from .test_module import * |
diff --git a/tests/test_suite_override/sample_app/tests/test_module.py b/tests/test_suite_override/sample_app/tests/test_module.py
new file mode 100644
index 0000000..7e22265
-
|
+
|
|
| 1 | # -*- coding: utf-8 -*- |
| 2 | import unittest |
| 3 | from django.test.utils import IgnoreAllDeprecationWarningsMixin |
| 4 | |
| 5 | |
| 6 | class StubTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase): |
| 7 | |
| 8 | def test_void(self): |
| 9 | """ |
| 10 | This is actually a void test, just to check if it's loaded |
| 11 | """ |
| 12 | No newline at end of file |
diff --git a/tests/test_suite_override/tests.py b/tests/test_suite_override/tests.py
index c485b80..9025f32 100644
a
|
b
|
|
1 | 1 | import unittest |
2 | 2 | |
3 | 3 | from django.apps import apps |
4 | | from django.test.utils import IgnoreAllDeprecationWarningsMixin |
| 4 | from django.test.utils import (IgnoreAllDeprecationWarningsMixin, |
| 5 | override_settings) |
5 | 6 | |
6 | 7 | |
7 | 8 | def suite(): |
… |
… |
class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
|
24 | 25 | suite = build_suite(app_config) |
25 | 26 | self.assertEqual(suite.countTestCases(), 1) |
26 | 27 | |
| 28 | @override_settings(INSTALLED_APPS=['test_suite_override.sample_app']) |
| 29 | def test_build_tests(self): |
| 30 | """ |
| 31 | This test is for #22478 |
| 32 | |
| 33 | when an application has test directory with tests organized in different |
| 34 | modules inside the test directory, every application module must be |
| 35 | checked for the passed test labels. |
| 36 | """ |
| 37 | from django.test.simple import build_test |
| 38 | suite = build_test("sample_app.StubTest") |
| 39 | self.assertEqual(suite.countTestCases(), 1) |
| 40 | |
27 | 41 | |
28 | 42 | class SampleTests(unittest.TestCase): |
29 | 43 | """These tests should not be discovered, due to the custom suite.""" |