|
1
|
|
|
from django.conf import settings |
|
2
|
|
|
from django.test.runner import DiscoverRunner |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class DiscoverRunnerTriggerHappy(DiscoverRunner): |
|
6
|
|
|
""" |
|
7
|
|
|
A Django test runner that uses unittest2 test discovery. |
|
8
|
|
|
""" |
|
9
|
|
|
|
|
10
|
|
|
def run_tests(self, test_labels, extra_tests=None, **kwargs): |
|
11
|
|
|
""" |
|
12
|
|
|
Run the unit tests for all the test labels in the provided list. |
|
13
|
|
|
Except those in TEST_RUNNER_WHITELIST tuple |
|
14
|
|
|
|
|
15
|
|
|
Test labels should be dotted Python paths to test modules, test |
|
16
|
|
|
classes, or test methods. |
|
17
|
|
|
|
|
18
|
|
|
A list of 'extra' tests may also be provided; these tests |
|
19
|
|
|
will be added to the test suite. |
|
20
|
|
|
|
|
21
|
|
|
Returns the number of tests that failed. |
|
22
|
|
|
""" |
|
23
|
|
|
self.setup_test_environment() |
|
24
|
|
|
app_to_test = self.unwanted_apps() |
|
25
|
|
|
for installed_app in app_to_test: |
|
26
|
|
|
test_labels = test_labels + (installed_app,) |
|
27
|
|
|
suite = self.build_suite(test_labels, extra_tests) |
|
28
|
|
|
old_config = self.setup_databases() |
|
29
|
|
|
result = self.run_suite(suite) |
|
30
|
|
|
self.teardown_databases(old_config) |
|
31
|
|
|
self.teardown_test_environment() |
|
32
|
|
|
return self.suite_result(suite, result) |
|
33
|
|
|
|
|
34
|
|
|
@staticmethod |
|
35
|
|
|
def unwanted_apps(): |
|
36
|
|
|
installed_apps = frozenset(settings.INSTALLED_APPS) |
|
37
|
|
|
|
|
38
|
|
|
try: |
|
39
|
|
|
do_not_test = frozenset(settings.TEST_RUNNER_WHITELIST) |
|
40
|
|
|
except AttributeError: |
|
41
|
|
|
do_not_test = set() |
|
42
|
|
|
|
|
43
|
|
|
return installed_apps - do_not_test |
|
44
|
|
|
|