|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# coding: utf-8 |
|
3
|
|
|
""" |
|
4
|
|
|
Run Django Test with Python setuptools test command |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
REFERENCE: |
|
8
|
|
|
http://gremu.net/blog/2010/enable-setuppy-test-your-django-apps/ |
|
9
|
|
|
|
|
10
|
|
|
""" |
|
11
|
|
|
import os |
|
12
|
|
|
import sys |
|
13
|
|
|
|
|
14
|
|
|
def parse_args(): |
|
15
|
|
|
import optparse |
|
16
|
|
|
parser = optparse.OptionParser() |
|
17
|
|
|
parser.add_option('--where', default=None) |
|
18
|
|
|
opts, args = parser.parse_args() |
|
19
|
|
|
return opts.where |
|
20
|
|
|
|
|
21
|
|
|
def run_tests(base_dir=None, verbosity=1, interactive=False): |
|
22
|
|
|
base_dir = base_dir or os.path.dirname(__file__) |
|
|
|
|
|
|
23
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
|
24
|
|
|
sys.path.insert(0, os.path.join(base_dir, 'src')) |
|
25
|
|
|
sys.path.insert(0, os.path.join(base_dir, 'tests')) |
|
26
|
|
|
|
|
27
|
|
|
from django.conf import settings |
|
28
|
|
|
from django.test.utils import get_runner |
|
29
|
|
|
"""Run Django Test""" |
|
30
|
|
|
TestRunner = get_runner(settings) |
|
|
|
|
|
|
31
|
|
|
test_runner = TestRunner(verbosity=verbosity, |
|
32
|
|
|
interactive=interactive, failfast=False) |
|
33
|
|
|
|
|
34
|
|
|
import django |
|
35
|
|
|
if django.VERSION >= (1, 7): |
|
|
|
|
|
|
36
|
|
|
django.setup() |
|
37
|
|
|
|
|
38
|
|
|
if django.VERSION >= (1, 6): |
|
39
|
|
|
app_tests = [ |
|
40
|
|
|
'registration', |
|
41
|
|
|
'registration.contrib.notification', # registration.contrib.notification |
|
42
|
|
|
'registration.contrib.autologin', # registration.contrib.autologin |
|
43
|
|
|
] |
|
44
|
|
|
else: |
|
45
|
|
|
app_tests = [ |
|
46
|
|
|
'registration', |
|
47
|
|
|
'notification', # registration.contrib.notification |
|
48
|
|
|
'autologin', # registration.contrib.autologin |
|
49
|
|
|
] |
|
50
|
|
|
failures = test_runner.run_tests(app_tests) |
|
51
|
|
|
sys.exit(bool(failures)) |
|
52
|
|
|
|
|
53
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
54
|
|
|
base_dir = parse_args() |
|
55
|
|
|
run_tests(base_dir) |
|
56
|
|
|
|
|
57
|
|
|
|