Code

Ticket #6712: svn.diff

File svn.diff, 1.4 KB (added by alainD, 6 years ago)

diff file (modified file is django/test/simple.py)

Line 
1Index: django/test/simple.py
2===================================================================
3--- django/test/simple.py       (révision 7193)
4+++ django/test/simple.py       (copie de travail)
5@@ -73,6 +73,16 @@
6                 pass
7     return suite
8
9+def _get_all_tests_from_suite(suite):
10+    """Explore suite recursively to get _all_ tests in it
11+    """
12+    if isinstance(suite,unittest.TestCase):
13+        return [suite]
14+    else:
15+        all_tests = []
16+        [all_tests.extend(_get_all_tests_from_suite(sub_suite)) for sub_suite in getattr(suite,'_tests',[])]
17+        return all_tests
18+
19 def build_test(label):
20     """Construct a test case a test with the specified label. Label should
21     be of the form model.TestClass or model.TestClass.test_method. Returns
22@@ -92,6 +102,15 @@
23         if test_module:
24             TestClass = getattr(test_module, parts[1], None)
25
26+    # Couldn't find the test class; look in test suite
27+    if TestClass is None:
28+        suite = build_suite(app_module)
29+        all_tests = _get_all_tests_from_suite(suite)
30+        for test_in_suite in all_tests:
31+            if test_in_suite.__class__.__name__ == parts[1]:
32+                TestClass = test_in_suite.__class__
33+                break
34+
35     if len(parts) == 2: # label is app.TestClass
36         try:
37             return unittest.TestLoader().loadTestsFromTestCase(TestClass)