-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
52 lines (40 loc) · 1.26 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
"""
A standalone test runner script
"""
import os
import sys
# Make sure the app is (at least temporarily) on the import path.
APP_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, APP_DIR)
# Minimum settings required for django-contact-form to work.
SETTINGS_DICT = {
'BASE_DIR': APP_DIR,
'INSTALLED_APPS': (
'bitfield',
'bitfield.tests' # so the test model is found
),
'DATABASES': {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
},
}
}
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(['bitfield.tests'])
sys.exit(bool(failures))
if __name__ == '__main__':
run_tests()