parse_args()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
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
15
def parse_args():
16
    import optparse
17
    parser = optparse.OptionParser()
18
    parser.add_option('--where', default=None)
19
    opts, args = parser.parse_args()
20
    return opts, args
21
22
23
def run_tests(base_dir=None, apps=None, verbosity=1, interactive=False):
24
    base_dir = base_dir or os.path.dirname(__file__)
25
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
26
    sys.path.insert(0, os.path.join(base_dir, 'src'))
27
    sys.path.insert(0, os.path.join(base_dir, 'tests'))
28
29
    import django
30
    if django.VERSION >= (1, 7):
31
        django.setup()
32
33
    from django.conf import settings
34
    from django.test.utils import get_runner
35
    TestRunner = get_runner(settings)
36
    test_runner = TestRunner(verbosity=verbosity,
37
                             interactive=interactive, failfast=False)
38
    if apps:
39
        app_tests = [x.strip() for x in apps if x]
40
    else:
41
        app_tests = [
42
            'roughpages',
43
        ]
44
    failures = test_runner.run_tests(app_tests)
45
    sys.exit(bool(failures))
46
47
if __name__ == '__main__':
48
    opts, args = parse_args()
49
    run_tests(opts.where, args)
50