|
1 | 1 | #!/usr/bin/env python |
2 | 2 | import sys |
| 3 | + |
3 | 4 | import django |
4 | | -from django.conf import settings, global_settings as default_settings |
| 5 | +from django.conf import settings |
5 | 6 | from django.core.management import execute_from_command_line |
6 | | -from os import path |
7 | 7 |
|
8 | 8 | if not settings.configured: |
9 | | - module_root = path.dirname(path.realpath(__file__)) |
10 | | - |
11 | | - sys.path.insert(0, path.join(module_root, 'example')) |
12 | | - |
13 | | - if django.VERSION >= (1, 8): |
14 | | - template_settings = dict( |
15 | | - TEMPLATES = [ |
16 | | - { |
17 | | - 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
18 | | - 'DIRS': (), |
19 | | - 'OPTIONS': { |
20 | | - 'loaders': ( |
21 | | - 'django.template.loaders.filesystem.Loader', |
22 | | - 'django.template.loaders.app_directories.Loader', |
23 | | - ), |
24 | | - 'context_processors': ( |
25 | | - 'django.template.context_processors.debug', |
26 | | - 'django.template.context_processors.i18n', |
27 | | - 'django.template.context_processors.media', |
28 | | - 'django.template.context_processors.request', |
29 | | - 'django.template.context_processors.static', |
30 | | - 'django.contrib.auth.context_processors.auth', |
31 | | - ), |
32 | | - }, |
33 | | - }, |
34 | | - ] |
35 | | - ) |
36 | | - else: |
37 | | - template_settings = dict( |
38 | | - TEMPLATE_LOADERS = ( |
39 | | - 'django.template.loaders.app_directories.Loader', |
40 | | - 'django.template.loaders.filesystem.Loader', |
41 | | - ), |
42 | | - TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [ |
43 | | - 'django.core.context_processors.request', |
44 | | - ], |
45 | | - ) |
46 | | - |
47 | 9 | settings.configure( |
48 | | - DEBUG = False, # will be False anyway by DjangoTestRunner. |
49 | | - TEMPLATE_DEBUG = True, |
50 | | - DATABASES = { |
51 | | - 'default': { |
52 | | - 'ENGINE': 'django.db.backends.sqlite3', |
53 | | - 'NAME': ':memory:' |
54 | | - } |
| 10 | + DATABASES={ |
| 11 | + "default": { |
| 12 | + "ENGINE": "django.db.backends.sqlite3", |
| 13 | + "NAME": ":memory:", |
| 14 | + }, |
55 | 15 | }, |
56 | | - INSTALLED_APPS = ( |
57 | | - 'capture_tag', |
| 16 | + SITE_ID=1, |
| 17 | + INSTALLED_APPS=( |
| 18 | + "capture_tag", |
58 | 19 | ), |
59 | | - TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner' if django.VERSION < (1, 6) else 'django.test.runner.DiscoverRunner', |
60 | | - **template_settings |
| 20 | + MIDDLEWARE=(), |
| 21 | + TEMPLATES=[ |
| 22 | + { |
| 23 | + "BACKEND": "django.template.backends.django.DjangoTemplates", |
| 24 | + "DIRS": (), |
| 25 | + "OPTIONS": { |
| 26 | + "loaders": ( |
| 27 | + "django.template.loaders.filesystem.Loader", |
| 28 | + ), |
| 29 | + "context_processors": (), |
| 30 | + }, |
| 31 | + }, |
| 32 | + ], |
| 33 | + TEST_RUNNER="django.test.runner.DiscoverRunner", |
| 34 | + DEFAULT_AUTO_FIELD="django.db.models.BigAutoField", |
61 | 35 | ) |
62 | 36 |
|
| 37 | +DEFAULT_TEST_APPS = [ |
| 38 | + "capture_tag", |
| 39 | +] |
| 40 | + |
63 | 41 |
|
64 | 42 | def runtests(): |
65 | | - argv = sys.argv[:1] + ['test', 'capture_tag'] + sys.argv[1:] |
| 43 | + other_args = list(filter(lambda arg: arg.startswith("-"), sys.argv[1:])) |
| 44 | + test_apps = ( |
| 45 | + list(filter(lambda arg: not arg.startswith("-"), sys.argv[1:])) or DEFAULT_TEST_APPS |
| 46 | + ) |
| 47 | + argv = sys.argv[:1] + ["test", "--traceback"] + other_args + test_apps |
66 | 48 | execute_from_command_line(argv) |
67 | 49 |
|
68 | | -if __name__ == '__main__': |
| 50 | + |
| 51 | +if __name__ == "__main__": |
69 | 52 | runtests() |
0 commit comments