-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathruntests.py
executable file
·91 lines (73 loc) · 2.73 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
"""
A standalone test runner script, configuring the minimum settings
required for tests to execute.
Re-use at your own risk: many Django applications will require
different settings and/or templates to run their tests.
Inspired by James Bennett
https://www.b-list.org/weblog/2020/feb/03/how-im-testing-2020/
"""
import os
import sys
APP_DIR = os.path.abspath(os.path.dirname(__file__))
# Minimum settings required for the app's tests.
SETTINGS_DICT = {
"BASE_DIR": APP_DIR,
"INSTALLED_APPS": (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django_dumpdata_one",
"tests",
),
# Test cases will override this liberally.
# "ROOT_URLCONF": "django_registration.backends.activation.urls",
"DATABASES": {
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
},
"MIDDLEWARE": (
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
),
"SITE_ID": 1,
"TEMPLATES": [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(APP_DIR, "tests/templates")],
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
]
},
}
],
"MEDIA_URL": "https://media.example.com/",
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField"
}
def run_tests():
# Making Django run this way is a two-step process. First, call
# settings.configure() to give Django settings to work with:
from django.conf import settings
settings.configure(**SETTINGS_DICT)
# Then, call django.setup() to initialize the application cache
# and other bits:
import django
django.setup()
# Now we instantiate a test runner...
from django.test.utils import get_runner
TestRunner = get_runner(settings)
# And then we run tests and return the results.
test_runner = TestRunner(verbosity=2, interactive=True)
failures = test_runner.run_tests(["tests"])
sys.exit(bool(failures))
if __name__ == "__main__":
run_tests()